Jump to content

Quick Question


Btown2

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.