Chat freely about the open source Javascript projects for ESP8266

User avatar
By Trickuncle
#35734 Goal: read a slider control value in browser and pass it back to ESP8266 server to be used as parameter for pwm of pin.
This code reads the slider and in the last line prints it successfully to the page as a debug step. But the line that puts the x variable in the url results in the url looking like this:
http://192.168.1.174/?somevar= x
And then my Lua program borks at trying to use x as the pwm parameter. I have tried endless methods of converting the var x to a string but so far nothing works. This is my first exposure to javascript.

Can someone tell me how to successfully pass the slider value in the url? Thanks!!!

Code: Select allconn:send('<script>')
        conn:send('function myFunction() {')              
        conn:send('    var x = document.getElementById("cmd").value;')
        conn:send('    document.location.href=\"?somevar= x ";') 
        conn:send('    document.getElementById("demo").innerHTML =  x ;')
conn:send('}</script>')
User avatar
By trackerj
#35737 You can find a working HTML Slider in the MAINS Dimmer web interface example. Just take the HTML/script part of the code and adapt it for your needs.
User avatar
By Trickuncle
#35742 Hi trackerj! Your code is a few levels above my understanding at present but thanks for posting it!

Right now, I would love to find out why my javascript code doesn't function.
User avatar
By Trickuncle
#35779 Partial success!!! I modified the code to use this function: encodeURI(uri) and now it works in Mozilla Firefox and maybe MSIE. Unfortunately, it appears that Chrome is confused. This is unfortunate because I have an Android phone running chrome and it was my plan to use it to control the system.

Onward and sideways!

Code: Select all        conn:send('<script>')
        conn:send('function myFunction() {')               
        conn:send('    var x = document.getElementById("cmd").value;')
        conn:send('    document.getElementById("demo").innerHTML =  x ;')
        conn:send('     var uri = "\?somevar=" + x;')
        conn:send('     var enc = encodeURI(uri);')
        conn:send('     document.location.href=\enc;')         
        conn:send('}</script>')