xml - How do I read a variable output from an html form and use it in the webpage? -
ok, i've tried work - can't seem see way...
what trying have form ask index, when submit read xml file (bowlist.xml) , give me data matching index.
here entire code:
<!doctype html> <html> <body> <form action=""> bowl #: <input type="text" name="bowlidx" value="" /><br /> <input type="submit" value="submit" /> </form> <script type="text/javascript"> var index = <%=request.querystring(bowlidx)%> document.write('index ' + index) if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.open("get","bowlist.xml",false); xmlhttp.send(); xmldoc=xmlhttp.responsexml; document.write("<table border='1'>"); var x=xmldoc.getelementsbytagname("product"); (i=0;i<x.length;i++) { if(x[i].getelementsbytagname("id")[0].childnodes[0].nodevalue != index) continue; document.write("<tr><td>"); document.write(x[i].getelementsbytagname("id")[0].childnodes[0].nodevalue); document.write("</td><td>"); document.write(x[i].getelementsbytagname("code")[0].childnodes[0].nodevalue); document.write("</td><td>"); document.write(x[i].getelementsbytagname("image")[0].childnodes[0].nodevalue); document.write("</td></tr>"); } document.write("</table>");</script> </body> </html> i form, enter , submit index, , nothing happens.
where going wrong on this?
i should add javascript search work if enter existing index in "if(x[i].getelementsbytagname("id")[0].childnodes[0].nodevalue != index)" line.
in case want when page loads (i.e. after click submit button , page reloads), use line of server-side code set variable in javascript, so:
index = <%=request.querystring("bowlidx")%>
Comments
Post a Comment