Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-01-2012, 06:07 PM   PM User | #1
chrisboots
New Coder

 
Join Date: Jan 2012
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
chrisboots is an unknown quantity at this point
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)
}
chrisboots is offline   Reply With Quote
Old 03-01-2012, 06:16 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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";
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
chrisboots (03-01-2012)
Old 03-01-2012, 06:40 PM   PM User | #3
chrisboots
New Coder

 
Join Date: Jan 2012
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
chrisboots is an unknown quantity at this point
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
chrisboots is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:51 AM.


Advertisement
Log in to turn off these ads.