Click to See Complete Forum and Search --> : Dynamic JS and ASP combination


hismightiness
12-15-2003, 10:20 AM
So far, I cannot get this function to react the way I need it to. If I comment out the lines shown in the function below, then I get the text from a read-only field which contains a date and doesn't have a selectedIndex property.

This is a LARGE form containing over 100 fields. I only put an example containing the pertinent information. The actual source is available, if anyone needs it.

Has anyone else had any experience with this?
<html>

<head>
<title>Example</title>
<script>
var arrTrucks = new Array();
// Created by a specifically sorted ASP recordset
arrTrucks[0]="0";
arrTrucks[1]="123456";
arrTrucks[2]="456789";
arrTrucks[3]="789123";
arrTrucks[4]="159951";
// and so on...

function showMiles(num, elem, elem2){
/* Need to find a way to automatically update any future occurences of the same truck selection.
*
* - use the NUM variable and loop through all the combo boxes to check for the same index selection
* - parse the field name and get the name of the field of which to copy the value
* - add 1 to the value and set it to the current field selection
*/
var f = document.frmLocalDetail;
var elemNum = document.frmLocalDetail.length;

for (var x = 0; x <= elemNum; x++){
//var e = f.elements[x];
//if (document.frmLocalDetail.elements[x].type = "select"){
//if (e.type = "select"){
if (f.elements[x].selectedIndex == num){
x = x + 2;
document.getElementById(elem).value = f.elements[x].value + 1;
break;
// Currently, this returns a non-select field value
}
//}
}

if (document.getElementById(elem).value == ''){
document.getElementById(elem).value = arrTrucks[num];
}

// For troubleshooting only...
alert('elem = ' + elem + '\nelem2 = ' + elem2 + '\nnum = ' + num + '\nx = ' + x);
document.getElementById(elem2).focus();
}
</script>
</head>

<body>

<form action="" method="post">

<!-- THE FOLLOWING FIELDS REPEAT THEMSELVES 14 TIMES -->

<select name="cmb0" id="cmb0" onselect="showMiles(arrTrucks, 'cmb0', 'txt0');">
<!-- Created by same ASP recordset as above -->
<option value="unique0">Index 0</option>
<option value="unique1">Index 1</option>
<option value="unique2">Index 2</option>
<option value="unique3">Index 3</option>
<option value="unique4">Index 4</option>
<!-- and so on...-->
</select>

<!-- This is where the array goes... -->
<!-- On successive rows, this field may need to be the value of "difference" + 1 instead of the array value -->
<input type="text" name="startingMiles0" id="startingMiles0" size="25" value="" readonly />

<!-- This is where the NEW VALUE gets manually typed -->
<input type="text" name="endingMiles0" id="endingMiles0" size="25" value="" />

<!-- This is where the DIFFERENCE goes (separate function not shown) -->
<input type="text" name="difference0" id="difference0" size="25" value="" readonly />

<br /><br />

<!-- AND ANOTHER ROW, etc... (14 total) -->

</form>
</body>
</html>