...

View Full Version : If else help



chrisboots
03-01-2012, 07:07 PM
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


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

devnull69
03-01-2012, 07:16 PM
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


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";

chrisboots
03-01-2012, 07:40 PM
This is weird code ...

First of all:


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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum