I have the following code: <html> <head> <title>TEST</title> <script language="javascript"> function getFields(index) { var num=1; if (index !=0) num=2*index +1; return num; } function show(line) { var num=getFields(line); id=document.forms[0].elements[num-1].value; alert("id read with elements[num]="+id); if (id == null) alert("1. ID NULL"); id=document.forms["0"].elements["serv_"+line].value; alert("id read with elements[name]="+id); if (id == null) alert("2. ID NULL!"); } </script> <body> <%@page language="java" %> <center> <form onSubmit="return false" method="post" name="my_form" action=""> <table border=2> <tr> <td id='c_0' onclick='show(0)'> <input type=hidden value=null name="serv_0"> <input type=text readonly value="1" size=25> </td></tr> <tr> <td id='c_1' onclick='show(1)'> <input type=hidden value="SERV" name="serv_1"> <input type=text readonly value="2" size=25> </td></tr> </table> </form> </body> </html> Code (markup): Results: 1. When I click on the 1st cell, the alarms that are being fired are: - id read with elements[num] = null - id read with elements[name] = null AS YOU CAN SEE JS DOES NOT RECOGNIZED NULL! 2. When I click on the 2nd cell, - id read with elements[num] = SERV - id read with elements[name] = SERV
You should enclose your attribute values using double quotes, and instead of using null you should use an empty string: "" So, you should check against that empty string "", not null. replace this: <input type=hidden value=null name="serv_0"> <input type=text readonly value="1" size=25> Code (markup): with this: <input type="hidden" value="" name="serv_0"> <input type="text" readonly="true" value="1" size="25"> Code (markup):