Results 1 to 6 of 6

Thread: In Java Script how to Check Null Value?

  1. #1
    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

  2. #2
    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; }
    }

  3. #3
    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;
    }
    }

  4. #4
    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

  5. #5
    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.

  6. #6
    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.

Similar Threads

  1. Null pointer error in java
    By Elizabeth Allen in forum Software Development
    Replies: 5
    Last Post: 19-03-2010, 02:26 PM
  2. How to Check Null Value in C#?
    By sivaranjan in forum Software Development
    Replies: 4
    Last Post: 04-02-2010, 04:49 AM
  3. How to check java string not null or blank
    By Capper in forum Software Development
    Replies: 4
    Last Post: 30-07-2009, 07:11 PM
  4. SQL need to check null or empty string
    By B_Hodge in forum Software Development
    Replies: 3
    Last Post: 18-06-2009, 11:44 AM
  5. How to check CPU fan speed? Win32_Fan returns null
    By bluej in forum Windows Server Help
    Replies: 0
    Last Post: 20-03-2007, 07:18 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,009,820.09052 seconds with 17 queries