hismightiness
12-10-2003, 12:39 PM
** ASP Page **
I need the values of the combo box to be something specific for the form submission. The index will give me the placement in my DB output (the array) which I can then input into the textbox. I will have several of these, so I need the function to be flexible to be able to do that for each set of form fields.
Why would this give me the output "undefined" in the textbox (and the troubleshooting alert box)?
<html>
<head>
<title>Example</title>
<script type="text/JavaScript">
var arrTrucks = new Array();
/* dynamically created via ASP
* The output is actually MUCH larger than this
*/
arrTrucks[0]="0";
arrTrucks[1]="123456";
arrTrucks[2]="456789";
arrTrucks[3]="789123";
arrTrucks[4]="159951";
function setVal(num, elem)
{
document.getElementById(elem).value=arrTrucks[num];
// FOR TROUBLESHOOTING ONLY
alert('document.getElementById(' + elem + ').value = arrTrucks[' + num + ']; \narrTrucks[' + num + '] = ' + arrTrucks[num]);
}
</script>
</head>
<body>
<form action="" method="post">
<!-- THERE WILL BE SEVERAL SETS OF THESE ON THE SAME FORM -->
<select name="cmb0" id="cmb0" onchange="setVal(this.selectedIndex, 'txt0');">
<!-- These options are also created dynamically via ASP -->
<option value="uniqueValue0">Text 0</option>
<option value="uniqueValue1">Text 1</option>
<option value="uniqueValue2">Text 2</option>
<option value="uniqueValue3">Text 3</option>
<option value="uniqueValue4">Text 4</option>
</select>
<br />
<input type="text" name="txt0" id="txt0" size="25" value="" />
</form>
</body>
</html>EDITED:Removed the extra "t" in the alert line.
I need the values of the combo box to be something specific for the form submission. The index will give me the placement in my DB output (the array) which I can then input into the textbox. I will have several of these, so I need the function to be flexible to be able to do that for each set of form fields.
Why would this give me the output "undefined" in the textbox (and the troubleshooting alert box)?
<html>
<head>
<title>Example</title>
<script type="text/JavaScript">
var arrTrucks = new Array();
/* dynamically created via ASP
* The output is actually MUCH larger than this
*/
arrTrucks[0]="0";
arrTrucks[1]="123456";
arrTrucks[2]="456789";
arrTrucks[3]="789123";
arrTrucks[4]="159951";
function setVal(num, elem)
{
document.getElementById(elem).value=arrTrucks[num];
// FOR TROUBLESHOOTING ONLY
alert('document.getElementById(' + elem + ').value = arrTrucks[' + num + ']; \narrTrucks[' + num + '] = ' + arrTrucks[num]);
}
</script>
</head>
<body>
<form action="" method="post">
<!-- THERE WILL BE SEVERAL SETS OF THESE ON THE SAME FORM -->
<select name="cmb0" id="cmb0" onchange="setVal(this.selectedIndex, 'txt0');">
<!-- These options are also created dynamically via ASP -->
<option value="uniqueValue0">Text 0</option>
<option value="uniqueValue1">Text 1</option>
<option value="uniqueValue2">Text 2</option>
<option value="uniqueValue3">Text 3</option>
<option value="uniqueValue4">Text 4</option>
</select>
<br />
<input type="text" name="txt0" id="txt0" size="25" value="" />
</form>
</body>
</html>EDITED:Removed the extra "t" in the alert line.