noam76

xml to form input

Jun 22nd, 2021 (edited)
418
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. HTML:
  2. <body onload="obtenirVariables()">
  3. // this div is working, showing the sensor
  4.  <div id="sensor0"></div>
  5.  <form>
  6. // I want show inside the form but is not working.
  7. <input id="sensor0" type="text" name="S0max" maxlength="4" size="4">
  8. <input name='BT01' type='submit' value="Send">
  9.  </form>
  10. </body>
  11.  
  12.  
  13. javascript:
  14. function obtenirVariables(){
  15. var uniqueURL = "/reqEtatVariables" + "?aleatoire=" + Math.trunc(Math.random() * 1000000);
  16. var request = new XMLHttpRequest(); // http://www.toutjavascript.com/reference/ref-xmlhttprequest.php
  17.     request.onreadystatechange = function()
  18.     {
  19.      if (request.readyState == 4) {
  20.       if (request.status == 200) {
  21. document.getElementById("sensor0").innerHTML = this.responseXML.getElementsByTagName('sensor0')[0].childNodes[0].nodeValue;
  22.   }
  23.   }
  24.  }
  25. }
  26.  
  27. XML function
  28.  
  29. void handleXML(){
  30.   XML="<?xml version='1.0'?>";
  31.   XML+="<xml>";
  32.   XML+="<pumpstate>";
  33.   XML+= pumpstate;
  34.   XML+="</pumpstate>";
  35.   XML+="</xml>";
  36.  server.send(200,"text/xml",XML);
  37. }
  38.  
  39. server.on("/reqEtatVariables",handleXML);
RAW Paste Data