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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaScript If Statements

    I'm having trouble with my If Statements not working. The syntax is correct according to many sources. Do you think it could be the browser? Maybe there is a patch for this. Please respond if you have had similar problems. Thank you for any suggestions.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    show us some code?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #3
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is an example of one of my If statements that does not work. If I type a value other than 0, 1, or 2 the alert should pop up, but it doesn't. Any suggestions?

    function APGAR() {
    if(field.value==0 || field.value==1 || field.value==2) {
    var A=eval(document.REG.ACT.value);
    var P=eval(document.REG.PULSE.value);
    var G=eval(document.REG.GRIMACE.value);
    var AP=eval(document.REG.APP.value);
    var R=eval(document.REG.RESP.value);
    document.REG.TOTAL.value=A+P+G+AP+R;
    } else {
    alert("You must enter a 0, 1, or 2");
    field.focus();
    }
    }

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    hm...shouldn't be here somewere something like var somevalue= newString(); ? I think that math values and string characters are not the same thing...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Think Kor's got it there, forms return strings so you need to turn it into number format so your code will now be

    Code:
        var theVal = parseInt(field.value, 10);
        if (theVal >= 0 && theval <= 3) {


  •  

    Posting Permissions

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