Click to See Complete Forum and Search --> : Help on Javascript


zw1971
09-18-2003, 02:18 PM
who can tell me what's the difference between the following 2 popups?

alert(document_index_definition2[0])
var index=2
alert('document_index_definition'+index+[0])

I already defined document_index_definition as an array. why the first popup the value of the array, while the other just gives the 'document_index_definition20'?

Thanks

gil davis
09-18-2003, 02:33 PM
The second one is just concatenation of strings. If you wanted to access the object, you would have needed to envoke the function "eval()":
alert(eval('document_index_definition' + index + '[0]'));

zw1971
09-18-2003, 02:41 PM
Thank you so much.

I'm really a newbie in javascript. Another question: how can I write a form dynamically based on the listbox onChange() function? I have all the forms info stored in the javascript array.

Thanks again

gil davis
09-19-2003, 01:28 PM
One way would be to use a CASE statement based on the value of the selected OPTION. Another would be to use the value of the OPTION as the array index.

<form ...>
<select ... onchange="newAction(this.options[this.selectedIndex].value)">
<option value="Fruit">Fruit
<option value="Cereal">Cereal
</select>
</form>