You are here: irt.org | FAQ | JavaScript | Form | 10.1 | Q898 [ previous next ]
The most compact way is to store three different items of data in each of the options value property separated with &:
<script language="JavaScript"><!-- function updateForm(what,count) { selected = what.mySelect.selectedIndex; value = what.mySelect.options[selected].value; for (var i = 0, oldpos = -1; i<count-1; i++) { pos = value.indexOf('&',oldpos+1); data = value.substring(oldpos+1,pos); what.elements['text' + i].value = value.substring(oldpos+1,pos); oldpos = pos; } what.elements['text' + i].value = value.substring(oldpos+1,value.length) } //--></script> <form> <select name="mySelect" onChange="updateForm(this.form,3)"> <option value="red&hot&inside">0 <option value="black&warm&outside">1 <option value="blue&cold&above">2 </select> <input type="text" name="text0"> <input type="text" name="text1"> <input type="text" name="text2"> </form> <p> And another form with four text boxes: </p> <form> <select name="mySelect" onChange="updateForm(this.form,4)"> <option value="red&hot&inside&today">0 <option value="black&warm&outside&tomorrow">1 <option value="blue&cold&above&yesterday">2 </select> <input type="text" name="text0"> <input type="text" name="text1"> <input type="text" name="text2"> <input type="text" name="text3"> </form>
Which can be extended to hold as many items of data as required.