Aug 19, 2015

how to check for null value in javascript

var nameval= new String();
    var name1=document.getElementById("name").value;
 
 
 
it is better to compare the length insted comparing the value of the string in javascript...

For example, instead of comparing...
if(nameval == null)
{
  // your logic
}
you can verify...

if(nameval.length == 0)
{
 // your logic
}
 
You can simply check the values like this:
if (!myValue) { ... }
 
 
Checks if nothing is entered in the input box
 
if(nameval == "")
    {
    //code
    }
 
 

No comments:

Post a Comment