Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  142] [ 1]  / answers: 1 / hits: 111867  / 9 Years ago, thu, september 24, 2015, 12:00:00

I have below code and java script is throwing error Unable to get property 'value' of undefined or null reference. What am I doing wrong ? below is the sample code I am trying to execute to validate one input field.



<html lang=en xml:lang=en xmlns=http://www.w3.org/1999/xhtml>
<head>
<title></title>
<meta content=text/html;charset=iso-8859-2 http-equiv=content-type />

<script type=text/javascript>
function validate_frm_new_user_request()
{
alert('test');
valid = true;

if ( document.frm_new_user_request.u_isid.value == '' )
{
alert ( Please enter your valid ISID Information. );
document.frm_new_user_request.u_isid.focus();
valid = false;
}
return valid;
</script>
</head>
<body
<form method=post action= name='frm_new_user_request' id=frm_new_user_request onsubmit=return validate_frm_new_user_request();>
<center>
<table>
<tbody>

<tr align=left>
<td><Label>ISID<em>*:</Label><input maxlength=15 id=u_userid name=u_userid size=20 type=text/></td>
<td>

<tr>
<td align=center colspan=4>
<input type=image src=images/button/btn_create_request.gif border=0 ALT=Create New Request>

</td>
</tr>
</table>
</form>
</body>
</html>

More From » javascript

 Answers
4

The issue is how you're attempting to get the value. Things like...



if ( document.frm_new_user_request.u_isid.value == '' )


won't work. You need to find the element you want to get the value of first. It's not quite like a server side language where you can type in an object's reference name and a period to get or assign values.



document.getElementById('[id goes here]').value;


will work. Note: JavaScript is case-sensitive



I would recommend using:



var variablename = document.getElementById('[id goes here]');


or



var variablename = document.getElementById('[id goes here]').value;

[#64937] Tuesday, September 22, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maxinec

Total Points: 117
Total Questions: 116
Total Answers: 116

Location: Bangladesh
Member since Sat, Jan 23, 2021
3 Years ago
maxinec questions
;