As the title says... Chat on...

User avatar
By bijacz
#58538 Hi, I have something like that:

Code: Select allsrv=net.createServer(net.TCP, 60)
srv:listen(80,function(conn)
    conn:on("receive",function(client,payload)
        function SendData()

function runMyFuction()
            alert("OK")
            end

--a few lines of code in HTML

<input type="submit"name="BUTTON"value="Submit"onclick="runMyFunction(); return false">\

--a few line of code in HTML

end


And there is no messagebox when I click "Submit" on webpage, I don't know why. Can you tell if anyone has done messagebox and it works correctly? Please help! ;)
User avatar
By marcelstoer
#58540 This is completely wrong. 'runMyFunction' needs to be a JavaScript function executed in the browser. The NodeMCU Lua code needs to return something like this to the browser:

Code: Select all<script>
function runMyFunction(){
  alert("OK");
}
</script>

<input type="submit"name="BUTTON"value="Submit"onclick="runMyFunction(); return false">
User avatar
By bijacz
#58541 Yes :oops: , I found that minute later and changed. But still - messagebox hasn't been shown.

Code: Select all'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\
            <html><head>\
            <meta content="text/html; charset=utf-8"/>\
            <h2><body bgcolor="#FFFFFF"><h2>Pressure, temperature and humidity</h2>\
            <h3><font color="black">\
            <IMG SRC="http://appbalo.com/wp-content/uploads/2014/09/Barometer.png"WIDTH="64"HEIGHT="64"><br>\
            '..string.format("%.1f",pres)..'hPa<br><br>\
            <IMG SRC="http://esp8266.fancon.cz/common/tmp.gif"WIDTH="64"HEIGHT="64"><br>\
            '..string.format("%.1f",temp)..'&degC<br>\
            '..string.format("%.1f",fare)..'&degF<br><br>\
            <IMG SRC="http://esp8266.fancon.cz/common/hyg.gif"WIDTH="64"HEIGHT="64"><br>\
            '..humi..' %<br><br></font></h3>\
            <h4><form action="/"method="post">\
            Min temperature:<br>\
            <input type="number"name="variable1"value="'..variable1..'"><br>\
            Max temperature:<br>\
            <input type="number"name="variable2"value="'..variable2..'"><br><br>\
            <input type="submit"name="BUTTON"value="Submit"onclick="return myFunction()"><br></form>\
            <script function myFunction(){alert("msg");}/>\
            </h4></body></html>'


What's wrong now? Only warning: init.lua:77: only one tcp server allowed
User avatar
By marcelstoer
#58545
bijacz wrote:init.lua:77: only one tcp server allowed


This is self-explanatory, isn't it? You can't have more than one server i.e. you can't successfully call 'net.createServer()' more than once unless you destroy the running server in between. Run '<your-server-variable>:close()' to do so.