Click to See Complete Forum and Search --> : Dynamic Form Fields w/ Array & combo box onChange event


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.

TheBearMay
12-10-2003, 01:35 PM
It works for me once I correct the typo in the alert statement: ...arrtTrucks[num]); => arrTrucks[num]);

hismightiness
12-10-2003, 01:56 PM
Yeah, I just was informed of the typpo, but it was only in the post. The typpo doesn't appear in my live code though. Ugh!

I am still getting that "undefined" result...

TheBearMay
12-10-2003, 02:17 PM
Tried a few other things, but the only time I got the message was if I delayed the creation of the textbox or the array....Sorry.

hismightiness
12-10-2003, 02:28 PM
One single (seemingly unrelated) typpo elsewhere on the page messed this up! D'oh!

Sorry to waste everyone's time. Thanks for trying to help me anyway...

Happy holidays (if you celebrate them)!