Btown2 Posted December 1, 2009 Share Posted December 1, 2009 Why isn't my function btnClick() being called when the form is submitted?? <html> <head> <title>Test</title> <script type='text/javascript'> function btnClick() { alert("got called"); var field = document.getElementById("gID"); var txt = field.value; if(txt == "") { alert("You must enter a game ID."); return false; } else { alert("went down else path"); var state = getState(txt); document.write(state); return true; } } function getState(var id) { var xmlhttp; if(window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if(readyState == 4) { var response = xmlhttp.responseText; return response; } } var url = "returnCurrentGameState.php?id="+id; xmlhttp.open("GET",url,true); xmlhttp.send(null); } else { alert("Browser not supported."); } } </script> </head> <body> <center> <form onSubmit="return btnClick();"> <input id="gID" type="text"> <input type="submit" value="Submit"> </form> </center> </body> </html> Link to comment https://forums.phpfreaks.com/topic/183640-quick-question/ Share on other sites More sharing options...
rajivgonsalves Posted December 1, 2009 Share Posted December 1, 2009 because you got a javascript error on the page function getState(var id) ??? should be function getState(id) Link to comment https://forums.phpfreaks.com/topic/183640-quick-question/#findComment-969258 Share on other sites More sharing options...
Btown2 Posted December 1, 2009 Author Share Posted December 1, 2009 Thank you, that was driving me insane. Link to comment https://forums.phpfreaks.com/topic/183640-quick-question/#findComment-969264 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.