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

Thread: If else help

  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts

    If else help

    Hi, cant get this function to work how it should, if the days (var Diff)are less then 27 then textbox id="alow" should be the days * 100 . if the days are greater than 27 then its Math.round((Diff / 7) * 500). but if the price = 420 or 450 then it should be 2000 .. its probably something small and stupid ive missed. thanks in advanced

    Code:
    if (Diff < 28 && document.date.car.options[document.date.car.selectedIndex].value=="A" && document.date.rentalamount.value === "£420" || "£450" ) 
    {
    document.date.alow.value = "2000 Miles"
    }
    else if (Diff < 28) 
    {
    document.date.alow.value = Diff * 100 +" Miles"
    }
    	
    	
    else (Diff > 27 && document.date.car.options[document.date.car.selectedIndex].value=="A") 
    
    {
    document.date.alow.value = Math.round((Diff / 7) * 500)
    }

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    This is weird code ...

    First of all: You cannot use the chained notation document.date.alow if "alow" is the id of an element. Generally this notation can only be used for name attributes

    Try this
    Code:
    var miles = 0;
    var price = document.getElementById('rentalamount').value;
    if(Diff <= 27) {
       miles = Diff * 100;
    } else {
       miles = Math.round((Diff / 7) * 500);
    }
    
    if(price == "£420" || price == "£450") {
       miles = 2000;
    }
    
    document.getElementById('alow').value = miles + " Miles";

  • Users who have thanked devnull69 for this post:

    chrisboots (03-01-2012)

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by devnull69 View Post
    This is weird code ...

    First of all:

    THANK YOU!. kinda know it would be something stupid ive done wrong. thanks


  •  

    Posting Permissions

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