-
Mar 27th, 2011, 10:41 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] javascript listbox not working
I've made a taxi fare calculator using google maps, and now im trying to add extra functionality, but i cant get the following code to work.
The idea is that once its calculated and displayed the fare in "txtFare", then to find the fare for a "bus", its selected from the list box and multiply's "txtFare" by '1.50' and displays it in "txtTypeFare".
This function doesn't work, and i can't see why not.
Code:
function calcType() {
var VehType = document.getElementById("sVehicle").innerHTML;
var EstFare = document.getElementById("txtFare").value;
if (VehType = "car")
{document.getElementById("txtTypeFare").value = EstFare};
if (VehType = "estate")
{document.getElementById("txtTypeFare").value = EstFare * 1.25 };
if (VehType = "bus")
{document.getElementById("txtTypeFare").value = EstFare * 1.50};
if (VehType = "exec")
{document.getElementById("txtTypeFare").value = EstFare * 1.75};
}
HTML Code:
<b>Fare: </b>
<input id="txtFare" type="textbox" value="">
<input type="button" value="fare" onClick="calcFare();">
<b>Vehicle: </b>
<select id="sVehicle" onChange="calcType()">
<option value="car">Car</option>
<option value="estate">Estate</option>
<option value="bus">Mini-Bus</option>
<option value="exec">Executive</option>
</select>
<input id="txtTypeFare" type="textbox" value="">
Thanks in advance
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
Mar 27th, 2011, 12:02 PM
#2
Re: javascript listbox not working
This line is a problem:
Code:
var VehType = document.getElementById("sVehicle").innerHTML;
If you want to see what the VehType variable is being populated with, add alert(VehType); on the line after that; it's not what you want.
Switch to:
Code:
var VehType = document.getElementById("sVehicle").value;
Also, on your if statements, you're using = instead of ==. That means, in all of your if statements, VehType is being assigned a value, not evaluated for a value, and all of your if statements are evaluating to true (because variable assignment evaluates to true). So the only if statement that you'll see the effect of is the last one.
-
Mar 27th, 2011, 05:41 PM
#3
Thread Starter
Hyperactive Member
Re: javascript listbox not working
thanks for the advice on ==, its working correctly now.
chris1990
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
Mar 27th, 2011, 07:08 PM
#4
Re: javascript listbox not working
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|