javascript - Ajax submit using a button -
i using code page: http://www.w3schools.com/ajax/ajax_database.asp build ajax solution.
i getting there, code use onchange, use button submit, instead.
one of tries:
<!doctype html> <html> <head> <script> function showcustomer(str) { var xmlhttp; if (str=="") { document.getelementbyid("txthint").innerhtml=""; return; } if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("txthint").innerhtml=xmlhttp.responsetext; } } xmlhttp.open("get","getcustomer.asp?q="+str,true); xmlhttp.send(); } </script> </head> <body> <form action=""> <select name="customers"> <option value="">select customer:</option> <option value="alfki">alfreds futterkiste</option> <option value="norts ">north/south</option> <option value="wolza">wolski zajazd</option> </select> <input name="submit1" type="submit" onclick="showcustomer(this.value)" /> </form> <br> <div id="txthint">customer info listed here...</div> </body> </html>
onchange event on select element.
just tie event button element.
<button onclick="showcustomer()">submit</button> and desired customer in showcustomer() method
function showcustomer() { var str = document.getelementbyid("customers").value; . . . xmlhttp.open("get","getcustomer.asp?q="+str,true); xmlhttp.send(); }
Comments
Post a Comment