www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] what is wrong with this if statement

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Posts
    79

    resolved [RESOLVED] what is wrong with this if statement

    Ok please help me figure out whats going on here. The pop up Always comes up, even if the statement is false


    Code:
    function carage() {
    		
    	var car = passedData['car'];
        var agec = parseFloat(document.mail.age.value);
    
      if ( car == "I" || car == "J" && agec < 25)
      
      {
    alert('You Must Be Over 25 To Hire This Vechicle');
    
    
    }
    
    if ( car == "K" || car =="K2" || car =="L" || car =="J2" && agec < 28)
      
      {
    alert('You Must Be Over 28 To Hire This Vechicle');
    
    
    }
    
    }

  2. #2
    Join Date
    Aug 2007
    Posts
    3,767
    You might mean:
    Code:
    if ( (car == "I" || car == "J") && agec < 25)
    But you didn't tell us exactly what it's supposed to do!
    Great wit and madness are near allied, and fine a line their bounds divide.

  3. #3
    Join Date
    Dec 2011
    Posts
    79
    Quote Originally Posted by Declan1991 View Post
    You might mean:
    Code:
    if ( (car == "I" || car == "J") && agec < 25)
    But you didn't tell us exactly what it's supposed to do!
    yeah sorry, should have gone into more detail, this if for a online booking form,

    var car is a letter which matches a car on my fleet, letters I and J have a minimum age limit on 25 and K K2 L and J2 of 28,.

    var agec is linked to text box that once they have filled in there d.o.b it figuers out there age.

    what i need this to do is only fire if there age is under either 25 or 28.

    Looking with google chrome the script knows the age is over 28, but still fires the alert

  4. #4
    Join Date
    Aug 2007
    Posts
    3,767
    Yup, you need the brackets as I indicated for both if statements, works fine for me.
    Great wit and madness are near allied, and fine a line their bounds divide.

  5. #5
    Join Date
    Dec 2011
    Posts
    79
    Quote Originally Posted by Declan1991 View Post
    Yup, you need the brackets as I indicated for both if statements, works fine for me.
    Works, Thank you very much

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles