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="JavaS cript">
var firstArray = new Array("('Select one','',true,tr ue)",
"('first')" ,
"('second') ",
"('third')" );
var secondArray = new Array("('Select two','',true,tr ue)",
"('fourth') ",
"('fifth')" ,
"('sixth')" );
function populateLocatio n(inForm,select ed) {
var selectedArray = eval(selected + "Array");
for (var i=0; i < selectedArray.l ength; i++) {
eval("inForm.lo cation.options[i]=" + "new Option" + selectedArray[i]);
}
}
</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="JavaS cript">
<!--
function Trip_Time(loc) {
if (document.loc.l ocation.value == "first") {
document.loc.ti me1.value = "4:30";
document.loc.ti me2.value = "9:00"; }
else if (document.loc.l ocation.value == "second") {
document.loc.ti me1.value = "2:40";
document.loc.ti me2.value = "7:10"; }
else if (document.loc.l ocation.value == "third") {
document.loc.ti me1.value = "1:10";
document.loc.ti me2.value = "6:30"; }
else if (document.loc.l ocation.value == "fourth") {
document.loc.ti me1.value = "3:50";
document.loc.ti me2.value = "2:10"; }
else if (document.loc.l ocation.value == "fifth") {
document.loc.ti me1.value = "7:20";
document.loc.ti me2.value = "11:10"; }
else if (document.loc.l ocation.value == "sixth") {
document.loc.ti me1.value = "24:00";
document.loc.ti me2.value = "19:30"; }
else {
document.loc.ti me1.value = "0:00";
document.loc.ti me2.value = "0:00";
}
}
// -->
</SCRIPT>
</head>
<body>
<form method="POST" action="results .asp" name="loc">
<select name="region"
onChange="popul ateLocation(doc ument.loc,docum ent.loc.region. options[document.loc.re gion.selectedIn dex].value)">
<option selected value=''>Select Region</option>
<option value='first'>F irst set</option>
<option value='second'> Second set</option>
<option value='third'>t hird</option>
<option value='fourth'> fourth</option>
<option value='fifth'>f ifth</option>
</select>
<br>
<select name="location" onChange="Trip_ Time()">
<option value=''>Choose Region 1st</option>
<option value='first'>f irst</option>
<option value='second'> second</option>
<option value='third'>t hird</option>
<option value='fourth'> fourth</option>
<option value='fifth'>f ifth</option>
</select>
<br>
<label for="inTime">
<input type="text" name="inTime"
onblur="addTime s(this,this.for m.time1,
this.form.time2 )"></label>
<br>
<label for="inTime">
<input type="text" name="time1"></label>
<br>
<label for="inTime"><i nput type="text" name="time2"></label>
<br>
<input type="submit" value="Submit" name="B1"> <input type="reset"
value="Reset" name="B2">
</form>
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="JavaS cript">
var firstArray = new Array("('Select one','',true,tr ue)",
"('first')" ,
"('second') ",
"('third')" );
var secondArray = new Array("('Select two','',true,tr ue)",
"('fourth') ",
"('fifth')" ,
"('sixth')" );
function populateLocatio n(inForm,select ed) {
var selectedArray = eval(selected + "Array");
for (var i=0; i < selectedArray.l ength; i++) {
eval("inForm.lo cation.options[i]=" + "new Option" + selectedArray[i]);
}
}
</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="JavaS cript">
<!--
function Trip_Time(loc) {
if (document.loc.l ocation.value == "first") {
document.loc.ti me1.value = "4:30";
document.loc.ti me2.value = "9:00"; }
else if (document.loc.l ocation.value == "second") {
document.loc.ti me1.value = "2:40";
document.loc.ti me2.value = "7:10"; }
else if (document.loc.l ocation.value == "third") {
document.loc.ti me1.value = "1:10";
document.loc.ti me2.value = "6:30"; }
else if (document.loc.l ocation.value == "fourth") {
document.loc.ti me1.value = "3:50";
document.loc.ti me2.value = "2:10"; }
else if (document.loc.l ocation.value == "fifth") {
document.loc.ti me1.value = "7:20";
document.loc.ti me2.value = "11:10"; }
else if (document.loc.l ocation.value == "sixth") {
document.loc.ti me1.value = "24:00";
document.loc.ti me2.value = "19:30"; }
else {
document.loc.ti me1.value = "0:00";
document.loc.ti me2.value = "0:00";
}
}
// -->
</SCRIPT>
</head>
<body>
<form method="POST" action="results .asp" name="loc">
<select name="region"
onChange="popul ateLocation(doc ument.loc,docum ent.loc.region. options[document.loc.re gion.selectedIn dex].value)">
<option selected value=''>Select Region</option>
<option value='first'>F irst set</option>
<option value='second'> Second set</option>
<option value='third'>t hird</option>
<option value='fourth'> fourth</option>
<option value='fifth'>f ifth</option>
</select>
<br>
<select name="location" onChange="Trip_ Time()">
<option value=''>Choose Region 1st</option>
<option value='first'>f irst</option>
<option value='second'> second</option>
<option value='third'>t hird</option>
<option value='fourth'> fourth</option>
<option value='fifth'>f ifth</option>
</select>
<br>
<label for="inTime">
<input type="text" name="inTime"
onblur="addTime s(this,this.for m.time1,
this.form.time2 )"></label>
<br>
<label for="inTime">
<input type="text" name="time1"></label>
<br>
<label for="inTime"><i nput type="text" name="time2"></label>
<br>
<input type="submit" value="Submit" name="B1"> <input type="reset"
value="Reset" name="B2">
</form>
Comment