Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 04-02-2010
Member
 
Join Date: Aug 2006
Posts: 155
In Java Script how to Check Null Value?

I want something for checking the null value. Actually I have just read that using the null parameters in Javascript allows programmers to define a variable without assigning a value to it. But I don't know anything about the checking that.!? Can anyone tell me how to Check Null Value in Java Script..?? It would be really appreciable if you provide some sample of the coding.! Thanks in Advance..!!
__________________
Desktop * Athlon X2 4200 | 2048M RAM | 160G HD | 7600GT
MacMini * G4 1.33GHz | 512M RAM | 40G HD | Radeon 9200
Laptop * Sempron 2800 | 512M RAM | 60G HD
PDA * Dell Axim x51 | 128M Internal | 256M SD Card
Reply With Quote
  #2  
Old 04-02-2010
Member
 
Join Date: Mar 2008
Posts: 672
Re: In Java Script how to Check Null Value?

I have provided you with the coding that can be used for checking the entry in the field. Instead of telling you the logic I thought that it will be better if I provide you with the coding. In the following scenario either the field will return a zero length string, or a null value if the field is kept empty. Check the following coding :
Code:
function IsEmpty(aTextField) {
   if ((aTextField.value.length==0) ||
   (aTextField.value==null)) {
      return true;
   }
   else { return false; }
}
Reply With Quote
  #3  
Old 04-02-2010
Member
 
Join Date: Mar 2008
Posts: 349
Re: In Java Script how to Check Null Value?

I have used two parts in my code. Once you understand this code then you can make big coding for checking the Null Value in JavaScript. So just have a look of the coding that I have provided below :
Code:
function validate(){
if ((document.personal.emailid.value == "") && (document.personal.phoneno.value == "") && 
(document.personal.cell.value == "") && 
(document.personal.pager.value == ""))
{
alert('Please provide your contact information');
return false;
}
else if ((document.personal.emailid.value.length!=0) || (document.personal.emailid.value!=null) || (document.personal.emailid.value!= ""))
{
alert('Validate emailid');
return false;
}
}
Reply With Quote
  #4  
Old 04-02-2010
Member
 
Join Date: Aug 2006
Posts: 235
Re: In Java Script how to Check Null Value?

According to me the following is a perfect example of checking the null value in the JavaScript. So just have a look at the coding :
Code:
mystring = <%=(Results.Fields.Item("Postion").Value)%>
If
("mystring.length==0")
document.write ("close to");
else
document.write (mystring & "works fine");
)
__________________
3.2 (northwood)
2gig ram
ATI AIW X800xt 256mb
Gigabyte GA-8knxp 875p Chipset
Optiwrite 8X DVD Burner
Win XP PRO Sp2 (Works Perfectly)
2 SATA Raptor 74gig Raid 0
2 7200 IDE 320gig HD
Reply With Quote
  #5  
Old 04-02-2010
Member
 
Join Date: Jul 2006
Posts: 442
Re: In Java Script how to Check Null Value?

You will have to follow some steps for checking the null value in JavaScript :
  1. First you will have to declare the variable. For declaring the variable you can type the following code :
    Code:
    var myVal = null;
    By doing this the memory is allocated to the variable.
  2. Now you will have to evaluate if the variable is null. You may also want to execute code if the value is null in some cases. You can do this by writing the following code :
    Code:
    if (myVal== null) {
    
    }
    This statement provides a way to execute code only if myVal is null.
  3. Then you will need to evaluate if a variable is not null. You may want to run code when a value is not null in some cases. The "!" operator tells the compiler to run the statements if the result is false. Javascript runs statements if myVal is not null: in this statement.
    Code:
    if (!name) {
    
    }
__________________
"When they give you ruled paper, write the other way..." J.R.J.
Reply With Quote
  #6  
Old 04-02-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: In Java Script how to Check Null Value?

I think that you can make the coding for checking the null value. I want to tell you more about the null value. Because it is necessary to understand it before using it in the code. Using null parameters in Javascript allows programmers to define a variable without assigning a value to it. Actually in any programming language the null value plays the same role. Null values are used in simple variables like integers and strings, and they are used for objects on a web page. But many times you will find that using the null values for calculations or object manipulation becomes the headache. If you have a defined variable in your code, checking for null values prior to executing code limits the amount of errors.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "In Java Script how to Check Null Value?"
Thread Thread Starter Forum Replies Last Post
Null pointer error in java Elizabeth Allen Software Development 5 19-03-2010 02:26 PM
How to Check Null Value in C#? sivaranjan Software Development 4 04-02-2010 04:49 AM
How to check java string not null or blank Capper Software Development 4 30-07-2009 07:11 PM
SQL need to check null or empty string B_Hodge Software Development 3 18-06-2009 11:44 AM
How to check CPU fan speed? Win32_Fan returns null bluej Windows Server Help 0 20-03-2007 07:18 PM


All times are GMT +5.5. The time now is 02:12 AM.