Cannot Read Value from Drop Down Script

D

Dan

This is one that has me stumped and I need an expert's input.

Any ideas why the values from the second script-generated drop down
list isn't recognized by the script to add time values to the text
boxes?

What this script is suppose to do is change the value of a second drop
down list based on the selection from the first.

Then a value is chosen from the script generated drop down list in the
second box.

This second drop down box value then runs a script that fills in the
blanks of 2 text fields with 2 different values based on the selection
from the second drop down box.

It works except the value selected in the second drop down box is not
recognized by the script to populate the 2 text fields.

I have manually added them to the second drop down box. If they are
chosen before the first drop down box scipt is run it works fine.

But if they are selected after running the first drop down box script,
the script that adds the value to the text fields views it as empty.




<SCRIPT LANGUAGE="JavaScript">

var firstArray = new Array("('Select one','',true,true)",
"('first')",
"('second')",
"('third')");

var secondArray = new Array("('Select two','',true,true)",
"('fourth')",
"('fifth')",
"('sixth')");

function populateLocation(inForm,selected) {
var selectedArray = eval(selected + "Array");

for (var i=0; i < selectedArray.length; i++) {
eval("inForm.location.options=" + "new Option" + selectedArray);
}
}
</script>

<script type="text/javascript">
function addTimes(a,b,c) {
if (a.value != '') {
/* Validate input here to check time entered is
of correct hh:mm format and within required range
Handle error if is isn't
*/
}
var t0 = a.value.split(':');
var t1 = b.value.split(':');
var t2 = c.value.split(':');

var m1 = +t0[1] + +t1[1];
var h1 = +t0[0] + +t1[0] + Math.floor(m1/60);
m1 = (m1 % 60);
b.value = h1 + ':' + m1;

var m2 = +t0[1] + +t2[1];
var h2 = +t0[0] + +t2[0] + Math.floor(m2/60);
m2 = (m2 % 60);
c.value = h2 + ':' + m2;
}
</script>




<script language="JavaScript">
<!--

function Trip_Time(loc) {
if (document.loc.location.value == "first") {
document.loc.time1.value = "4:30";
document.loc.time2.value = "9:00"; }

else if (document.loc.location.value == "second") {
document.loc.time1.value = "2:40";
document.loc.time2.value = "7:10"; }

else if (document.loc.location.value == "third") {
document.loc.time1.value = "1:10";
document.loc.time2.value = "6:30"; }

else if (document.loc.location.value == "fourth") {
document.loc.time1.value = "3:50";
document.loc.time2.value = "2:10"; }

else if (document.loc.location.value == "fifth") {
document.loc.time1.value = "7:20";
document.loc.time2.value = "11:10"; }

else if (document.loc.location.value == "sixth") {
document.loc.time1.value = "24:00";
document.loc.time2.value = "19:30"; }

else {
document.loc.time1.value = "0:00";

document.loc.time2.value = "0:00";

}
}

// -->
</SCRIPT>

</head>

<body>



<form method="POST" action="results.asp" name="loc">

<select name="region"
onChange="populateLocation(document.loc,document.loc.region.options[document.loc.region.selectedIndex].value)">
<option selected value=''>Select Region</option>
<option value='first'>First set</option>
<option value='second'>Second set</option>
<option value='third'>third</option>
<option value='fourth'>fourth</option>
<option value='fifth'>fifth</option>
</select>

<br>



<select name="location" onChange="Trip_Time()">
<option value=''>Choose Region 1st</option>
<option value='first'>first</option>
<option value='second'>second</option>
<option value='third'>third</option>
<option value='fourth'>fourth</option>
<option value='fifth'>fifth</option>
</select>
<br>




<label for="inTime">
<input type="text" name="inTime"
onblur="addTimes(this,this.form.time1,
this.form.time2)"></label>
<br>


<label for="inTime">

<input type="text" name="time1"></label>

<br>
<label for="inTime"><input type="text" name="time2"></label>
<br>
<input type="submit" value="Submit" name="B1"> <input type="reset"
value="Reset" name="B2">

</form>
 
K

kaeli

This is one that has me stumped and I need an expert's input.

Any ideas why the values from the second script-generated drop down
list isn't recognized by the script to add time values to the text
boxes?

What's with all the evals and stuff?

This is my script for doing dynamic select boxes. Check it out.
http://www.ipwebdesign.net/kaelisSpace/useful_dynamicSelects.html

--
--
~kaeli~
Never argue with an idiot! People may not be able to tell
you apart.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top