html - Javascript fails to get the value of a text input -
my code below works if manually set value of command
, if try value dynamically code stops working altogether. isolated line of code seems problem(comment after saying error is).
if comment line alert(document.getelementbyid("cdmtxt").value);
works intended.
<?php session_start(); ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="en-us" http-equiv="content-language" /> <meta content="text/html; charset=utf-8" http-equiv="content-type" /> <script type='text/javascript'> function exec(){ alert("hi"); alert(document.getelementbyid("cdmtxt").value); //does not seem execute??? var command = "word"; var xmlhttp = new xmlhttprequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readystate == 4 && xmlhttp.status == 200) { var txttoupdate = document.getelementbyid("txthint"); txttoupdate.innerhtml = txttoupdate.innerhtml + xmlhttp.responsetext + "<br/><br/>"; } } xmlhttp.open("get", "has-sync.php?exec=" + command, true); xmlhttp.send(); } </script> <style type="text/css"> .auto-style1 { margin-top: 0px; } </style> </head> <body> <table style="width: 100%"> <tr> <td style="width: 141px; height: 390px">managers<br /> dhts</td> <td name="targetthing" style="height: 390px"> <form onsubmit="exec();return false"> <input id="cmdtxt" class="auto-style1" name="text1" type="text"> <input type="submit"> </form> <br /> <div id="txthint" style="overflow: scroll; border:1px solid black;width:80%;height:80%"></div> </td> </tr> </table> </body> </html>
any appreciated!
you have typo:
getelementbyid("cdmtxt") // should "cmdtxt"
Comments
Post a Comment