PDA

View Full Version : Jscript Won't work in NS


karen
01-18-2001, 11:49 AM
I have what I thought was a very simple form, unfortunately, it's not working in Netscape.

Here's the script:
<script language="javascript">

function analysis(traffic)
{ var time,cars,count;

time=(traffic.time.value)
cars=(traffic.cars.value)
count=(traffic.count.value)
traffic.count.value=(traffic.time.value*traffic.cars.value);
}

</script>

Here's the form:
<form name="traffic">
Time:
<select size="1" name="time">
<option value="80">9:00 - 9:45 am</option>
<option value="82.52">9:46 am</option>
<option value="82.19">9:47 am</option>
<option value="81.71">9:48 am</option>
<option value="81.39">9:49 am</option>
</select>

<p>Vehicles:
<input type="text" name="cars" onChange="analysis(traffic)"></p>
Count:  <input type="text" name="count" size="20">
<p><input type="reset" value="Reset"></p>
</form>

I thought I was keeping it nice and simple, but apparently I don't know WHAT I'm doing, because NS only returns a value of 0.

I'm just beginning with JS, so any help would be very very appreciated!!

Thanks in advance!

kdjoergensen
01-18-2001, 05:42 PM
when you need to extract a value of a select element (commonly referred to as a 'drop down box') the syntax is:

with (document.traffic.time) {
time = options[selectedIndex].value;
}

Actually the entire syntax is:
document.traffic.time.options[document.traffic.time.selectedIndex].value but the short cut via the with() command makes it easier to read.

Should work now.