How to Solve JavaScript NULL Error

Posted by Sivakumar.S under JavaScript on 6/1/2012 | Points: 10 | Views : 1151 | Status : [Member] | Replies : 2
Hi,

In Javascript, i am getting null error while the values are checking in the loop. For your information, in my project i already get the element id and after that through that id, i am checking the value is nothing. That time the error is displaying. How can i solve this null error, pls guide me..

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

txtCtrl = document.getElementById('<%=txtRECornealReflex.ClientID%>');

if (txtCtrl.value == "")


$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

The Error is like: Error: 'value' is null or not an object
code:0

siva


Responses

Posted by: Gaur1982 on: 6/1/2012 [Member] Starter | Points: 25

Up
0
Down
Please improve this code and check it first i.e. txtCtrl is not equl to null....
txtCtrl = document.getElementById('<%=txtRECornealReflex.ClientID%>');

if (txtCtrl.value == "")


Corrected code
txtCtrl = document.getElementById('<%=txtRECornealReflex.ClientID%>');

if (txtCtrl != null)
{
if (txtCtrl.value == "")
....
....



Gaurav Agrawal
http://www.planetofcoders.com/

Sivakumar.S, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 6/4/2012 [Member] Starter | Points: 25

Up
0
Down
txtCtrl = document.getElementById('<%=txtRECornealReflex.ClientID%>');

if (txtCtrl != null && txtCtrl != undefined)
{
if (txtCtrl.value == "")
....
....
}


rewrite your Code Like this.

Enjoy

Ajay
ajaypatelfromsanthal.blogspot.in

Sivakumar.S, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response