Jump to content

Is Null Or Not An Object


user4fun

Recommended Posts

I keep getting the document.getElementById(...) is null or not an object

<html><head><title></title></head><script type="text/javascript">var http = false;if(navigator.appName == "Microsoft Internet Explorer") {  http = new ActiveXObject("Microsoft.XMLHTTP");} else {  http = new XMLHttpRequest();}function validate(objName, objValue){var objResponse = document.getElementById("Msg_" + objName);  var params = "";  if(objName == "username")  {	params = "?name=" + objValue;  }   if(objName == "pwd")  {	 params = "?pwd=" + objValue;  }   if(objName == "email")  {	 params = "?email=" + objValue;  }  if(objName == "phone")  {	 params = "?phone=" + objValue;  } http.open("GET", "validate_form.php" + params, true);  http.onreadystatechange=function()	{	if(http.readyState == 4)		{	//This is where it is saying that the error is.  document.getElementById(objResponse).innerHTML = http.responseText;		}	  }  http.send(null);}</script><body><div align="center"> <form name="signup"><br><div id="Msg_username" </div><br>Your user name: <input type="text" name="username" id="username" size="26" maxlength="50" type="text" tabindex="1" onchange="validate('username', this.value)"/><br><div id="Msg_pwd" </div><br>Your password:  <input type="text" name="pwd" id="pwd" size="26" maxlength="25"  type="password" tabindex="2" onchange="validate('pwd', this.value)"/><br><div id="Msg_email" </div><br>Your email:   <input type="text" name="email" id="email" size="36" maxlength="36" tabindex="3" value="myemail@somewhere.com" onchange="validate('email', this.value)"/><br><div id="Msg_phone" </div><br>Cell phone number: <input name="phone" id= "phone" size="26" maxlength="25" type="text" size="20" tabindex="4" onchange="validate('phone', this.value)"/><br><input name="Submit" value="Create Account" type="submit" 	tabindex="6"> </form>			  </body></html>

Link to comment
Share on other sites

for 1, you should put the script in the head section of your page<html>

<head><title></title><script type="text/javascript">...script here...</script></head>

Also, most of your div tags are not closed

<div id="Msg_email" </div>
make them
<div id="Msg_email"></div>

the main reason for your problem, if i am correct (besides the above problem) is that this line is incorrect:

document.getElementById(objResponse).innerHTML = http.responseText;

it should be

objResponse.innerHTML = http.responseText;

Link to comment
Share on other sites

Thank you so much, I did just run into another issue that I am kind off lost in.in my validation page, how would I know which params was submitted

if(objName == "username")  {	params = "?name=" + objValue;  }   if(objName == "pwd")  {	 params = "?pwd=" + objValue;  }   if(objName == "email")  {	 params = "?email=" + objValue;  }  if(objName == "phone")  {	 params = "?phone=" + objValue;  }

in my validate_form.php, I need to know which one I am going to try validating, so I only send back the result to the text field that was just changed.

Link to comment
Share on other sites

That is not going to do it$_GET['name'],, what if I am trying to get the $_GET['pwd'], then what. I cannot have a $_GET for aech one because if the use is working on the user name, then it will be send to the alidate_form.php and comes back with intructions. If I also have a $_GET['pwd'] at the same time, then another response will be send back saying that the pwd is empty. When in fact the user has not even gotten there yet.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...