I have a selection box created in javascript using createElement. When the user selects one of the selections and then presses the onSubmit button, the value of the selected item goes back to the default, it doesn't stay on the users selected item. How can i make it stay on the selected item.
Well i have a submit button called 'LOAD' which does a query into the database to find a match. here's the code, a little complex: <SELECT NAME="firstChoice" ID="firstChoice" ONCHANGE="selectChange(this, genericform.secondChoice, arrItems1, arrItemsGrp1);"> <OPTION VALUE="Select Unit" selected <?php if(@strcmp($_POST['firstChoice'], 'Select Unit') == 0) echo "SELECTED";?>> Select Unit </OPTION> <OPTION VALUE="SDC1-2" <?php if(@strcmp($_POST['firstChoice'], 'SDC1-2') == 0) echo "SELECTED";?>> SDC1-2 </OPTION> <OPTION VALUE="P73 Kit" <?php if(@strcmp($_POST['firstChoice'], 'P73 Kit') == 0) echo "SELECTED";?>> P73 Kit </OPTION> <OPTION VALUE="MDR2-2" <?php if(@strcmp($_POST['firstChoice'], 'MDR2-2') == 0) echo "SELECTED";?>> MDR2-2 </OPTION> <OPTION VALUE="CSD1-3" <?php if(@strcmp($_POST['firstChoice'], 'CSD1-3') == 0) echo "SELECTED";?>> CSD1-3 </OPTION> <OPTION VALUE="CSD1-4" <?php if(@strcmp($_POST['firstChoice'], 'CSD1-4') == 0) echo "SELECTED";?>> CSD1-4 </OPTION> <OPTION VALUE="MLS1-1" <?php if(@strcmp($_POST['firstChoice'], 'MLS1-1') == 0) echo "SELECTED";?>> MLS1-1 </OPTION> </SELECT></B> <BR><B><FONT SIZE=4>Unit Part # <SELECT NAME="secondChoice" ID="secondChoice" ONCHANGE="showLoad()"></FONT> <INPUT TYPE=submit VALUE="Load" NAME="loadData" ID="loadData" STYLE="display:none;"> <SCRIPT LANGUAGE="Javascript" TYPE="text/javascript"> var arrItems1 = new Array(); var arrItemsGrp1 = new Array(); arrItems1[0] = "304315-701"; arrItemsGrp1[0] = 'SDC1-2'; arrItems1[1] = "304315-702"; arrItemsGrp1[1] = 'SDC1-2'; arrItems1[2] = "304315-703"; arrItemsGrp1[2] = 'SDC1-2'; arrItems1[3] = "304315-704"; arrItemsGrp1[3] = 'SDC1-2'; arrItems1[4] = "304315-705"; arrItemsGrp1[4] = 'SDC1-2'; arrItems1[5] = "304315-706"; arrItemsGrp1[5] = 'SDC1-2'; arrItems1[6] = "304316-701"; arrItemsGrp1[6] = 'P73 Kit'; arrItems1[7] = "304316-702"; arrItemsGrp1[7] = 'P73 Kit'; arrItems1[8] = "304316-703"; arrItemsGrp1[8] = 'P73 Kit'; arrItems1[9] = "304316-704"; arrItemsGrp1[9] = 'P73 Kit'; arrItems1[10] = "304317-701"; arrItemsGrp1[10] = 'MDR2-2'; arrItems1[11] = "304317-702"; arrItemsGrp1[11] = 'MDR2-2'; arrItems1[12] = "304318-701"; arrItemsGrp1[12] = 'CSD1-3'; arrItems1[13] = "304318-702"; arrItemsGrp1[13] = 'CSD1-3'; arrItems1[14] = "304318-703"; arrItemsGrp1[14] = 'CSD1-3'; arrItems1[15] = "304319-701"; arrItemsGrp1[15] = 'CSD1-4'; arrItems1[16] = "304319-702"; arrItemsGrp1[16] = 'CSD1-4'; arrItems1[17] = "304319-703"; arrItemsGrp1[17] = 'CSD1-4'; arrItems1[18] = "304320-701"; arrItemsGrp1[18] = 'MLS1-1'; function selectChange(control, controlToPopulate, ItemArray, GroupArray) { var myEle; var x; // Empty the second drop down box of any choices for (var q = controlToPopulate.options.length; q >= 0; q--) { controlToPopulate.options[q] = null; } // ADD Default Choice - in case there are no values myEle = document.createElement("option"); theText = document.createTextNode("Select Part #"); myEle.appendChild(theText); myEle.setAttribute("value", "0"); controlToPopulate.appendChild(myEle); // Now loop through the array of individual items // Any containing the same child id are added to // the second dropdown box for ( x = 0; x < ItemArray.length; x++ ) { if ( GroupArray[x] == control.value ) { myEle = document.createElement("option"); myEle.setAttribute(ItemArray[x], x); var txt = document.createTextNode(ItemArray[x]); myEle.appendChild(txt) controlToPopulate.appendChild(myEle) } } } Code (markup):