Javascript Unable to get property value 'w90> or null reference

I have the code below and the java script is throwing error "Unable to get property value 'from undefined or null reference". What am I doing wrong? below is an example of the code I'm trying to execute to validate a single 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> 
+5
source share
3 answers

The problem is how you are trying to get the value. Such things as...

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

will not work. You need to find the item that you want to get first. This does not quite resemble a server-side language, where you can enter the name of the object reference and the period to receive 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; 
+4
source

You cannot access an element like you ( document.frm_new_user_request ). You should use the getElementById function:

document.getElementById("frm_new_user_request")

Thus, getting the value from the input might look like this:

var value = document.getElementById("frm_new_user_request").value

You can also use some JavaScript environment, for example. jQuery , which simplifies operations with the DOM (Document Object Model), and also hides from you the differences between different browsers.

Getting a value from input using jQuery will look like this:

  • with ID element ": var value = $("#element).value
  • with class element ": var value = $(".element).value
+1
source

you have a lot of HTML and java script errors: with a tag, using UTF-8 encoding to submit the form is not necessary ... You should use document.forms.FORMNAME or document.forms[0] for the first form on the page Fixed:

  function validate_frm_new_user_request() { alert('test'); var valid = true; if ( document.forms.frm_new_user_request.u_userid.value == "" ) { alert ( "Please enter your valid ISID Information." ); document.forms.frm_new_user_request.u_userid.focus(); valid = false; console.log("FALSE::Empty Value "); } return valid; } 
 <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta content="text/html;charset=UTF-8" http-equiv="content-type" /> </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> <tr align="left"> <td><Label>ISID<em>*:</Label><input maxlength="15" id="u_userid" name="u_userid" size="20" type="text"/></td> </tr> <tr> <td align="center" colspan="4"> <input type="image" src="btn.png" border="0" ALT="Create New Request"> </td> </tr> </table> </form> </body> </html> 
0
source

Source: https://habr.com/ru/post/1232208/


All Articles