Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## 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)
}```

• 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)

• Originally Posted by devnull69
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
•