Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    34
    Thanks
    7
    Thanked 0 Times in 0 Posts

    How to check for Nan whilst checking for "" aswell

    Hi All,

    i have a javascript function which i pass 3 fields to which then check to see if they are empty but the two other fields txtDeveloperDetailEstimate and TxtAldonTaskNumber are numeric and i need to check for != NaN but when i fill something in to the comment area it comes back as red even though there is some text in it, how can i check for the numeric values of the other two without interupting the first check for comments etc?

    Code:
    var DevFieldCheck = Array('MainDisplayContentChange_txtDeveloperComment', 'MainDisplayContentChange_txtDeveloperDetailEstimate', 'MainDisplayContentChange_txtAldonTaskNumber');
    var obj;
    function DevItemCheck(windowname) {
        for (var i = 0; i < DevFieldCheck.length; i++) {
            obj = document.getElementById(DevFieldCheck[i]);
    
            if (obj.value == "" || obj.value == 0 || obj.value != NaN) 
            {
                obj.style.backgroundColor = "#B20635";
                return false;
            }
    
        }
        Businesspopup(windowname)
    }
    Any help will be highly appreciated.
    **Update**
    Iv tried this aswell but it still turns red when there is a number in there

    Code:
    var DevFieldCheck = Array('MainDisplayContentChange_txtDeveloperComment');
    var obj;
    function DevItemCheck(windowname) 
    {
        for (var i = 0; i < DevFieldCheck.length; i++) 
        {
            obj = document.getElementById(DevFieldCheck[i]);
    
            if (obj.value == "" || obj.value == 0) {
                obj.style.backgroundColor = "#B20635";
                return false;
            }
       }
    
    
    
       if (document.getElementById('MainDisplayContentChange_txtDeveloperDetailEstimate').value = NaN)
        {
            document.getElementById('MainDisplayContentChange_txtDeveloperDetailEstimate').style.backgroundColor = "#B20635";
               return false;
           }
        if (document.getElementById('MainDisplayContentChange_txtAldonTaskNumber').value == NaN) 
        {
            document.getElementById('MainDisplayContentChange_txtAldonTaskNumber').style.backgroundColor = "#B20635";
                 return false;
             }
       AnotherDevpopup(windowname)
    }
    Im aware i have one line with "=" and the other with "==" i was testing both out...to see if it made a difference
    Last edited by Scott.Atkinson; 09-24-2011 at 11:06 AM.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,513
    Thanks
    3
    Thanked 504 Times in 491 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script  type="text/javascript">
    /*<![CDATA[*/
    var DevFieldCheck = Array('MainDisplayContentChange_txtDeveloperComment', 'MainDisplayContentChange_txtDeveloperDetailEstimate', 'MainDisplayContentChange_txtAldonTaskNumber');
    
    function DevItemCheck(windowname) {
        for (var obj,reg=new RegExp('\\bnumber\\b'),i = 0; i < DevFieldCheck.length; i++) {
            obj = document.getElementById(DevFieldCheck[i]);
    
            if (!obj.value||(reg.test(obj.className)&&isNaN(obj.value)))
            {
                obj.style.backgroundColor = "#B20635";
     //           return false;
            }
    
        }
    //   Businesspopup(windowname)
    }
    
    /*]]>*/
    </script>
    </head>
    
    <body>
    <input name="" id="MainDisplayContentChange_txtDeveloperComment" />
    <input name="" class="myclass number" id="MainDisplayContentChange_txtDeveloperDetailEstimate" />
    <input name="" class="number" id="MainDisplayContentChange_txtAldonTaskNumber" />
    <input type="button" name="" value="TEST" onmouseup="DevItemCheck();"/>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • Users who have thanked vwphillips for this post:

    Scott.Atkinson (09-24-2011)

  • #3
    New Coder
    Join Date
    Sep 2011
    Posts
    34
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Excellent thanks!! Works a charm!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •