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> Quote Link to comment 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) Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.