bindiya Posted December 18, 2010 Share Posted December 18, 2010 I have a html form. i have the fields like username,password,firstname,address. I have placed the username inside another form because onblur event this textfiels value should b recieved by the js. But js is not recieving the value.Gives the error'document.usercheck.username is null or nota an object. My code is <script language="javascript"> function submit_check(){ var name=document.usercheck.username.value; location.href="user_availability.php?login="+name; document.forms['usercheck'].submit(); } html------------- <form name='registration' action='' method='post' onsubmit="return verify();"> <table width="599" align='center'> <tr><td colspan='5'></td></tr> <tr><td width="33"></td> <td width="187"><!--UserName<suponblur='submit(this.value);'>onblur='submit_check(this.value);'--> User Name <font color="#CC0000">*</font></sup> </td> <td width="22">:</td> <td width="148"> <div> <form name='usercheck' method="post" action=''> <input name="username" type="text" id="username" value="" maxlength="15" onblur="submit_check();" /></td><td width="185"></form><</td> </tr> <tr><td width="33"></td> <td width="187">Password<sup><font color="#CC0000">*</font></sup></td> <td width="22">:</td> <td width="148"><input name="password" type='text' id='password' /></td><td></td></tr> <tr><td width="33"></td> <td width="187">Re Password<sup><font color="#CC0000">*</font></sup></td> <td width="22">:</td> <td width="148"><input name="repassword" type='text' id='repassword'/></td><td></td></tr> </table></form> Link to comment https://forums.phpfreaks.com/topic/222046-how-to-get-a-text-field-value-into-javascript-variable/ Share on other sites More sharing options...
brianlange Posted December 19, 2010 Share Posted December 19, 2010 You shouldn't be nesting forms. Use multiple submit buttons if this is the case. var name=document.usercheck.username.value; is correct for getting the input value. Link to comment https://forums.phpfreaks.com/topic/222046-how-to-get-a-text-field-value-into-javascript-variable/#findComment-1149303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.