Hi,
I have some code which I've adapted for a three tierd conditional drop down list. The first dropdown which is not included in the code is s simpe normal drop down list. The values of each dropdowns is submitted to a sql database. My problem is that if a user selects a value in the first drop down which has no children in the second or third, the third drop down will go blank and the value is submitted as NULL as oppsed to 0. I tried changing the line
" // Empty the third drop down box of any choices
for (var q=form.type3.options.length;q>=0;q--) form.type3.options[q] =null;"
- changing "null" to "0", but this totally wrecks the system. Please help
Code:<script type="text/javascript"> <!-- /* This script and many more are available free online at The JavaScript Source!! http://javascript.internet.com Revised by: DeWayne Whitaker :: http://www.aecdfw.com Original by: Andrew Berry */ var arrItems1 = new Array(); var arrItemsGrp1 = new Array(); arrItems1[3] = "String Ensemble"; arrItemsGrp1[3] = 3; arrItems1[4] = "Wind Ensemble"; arrItemsGrp1[4] = 3; arrItems1[5] = "Brass Ensemble"; arrItemsGrp1[5] = 3; arrItems1[6] = "Vocal Enselmble"; arrItemsGrp1[6] = 3; arrItems1[7] = "Blues/Jazz Group"; arrItemsGrp1[7] = 3; arrItems1[8] = "Rock/Pop Group"; arrItemsGrp1[8] = 3; arrItems1[9] = "Orchestra"; arrItemsGrp1[9] = 3; arrItems1[10] = "Choir"; arrItemsGrp1[10] = 3; arrItems1[12] = "Strings"; arrItemsGrp1[12] = 4; arrItems1[13] = "Woodwind"; arrItemsGrp1[13] = 4; arrItems1[14] = "Brass"; arrItemsGrp1[14] = 4; arrItems1[15] = "Guitar"; arrItemsGrp1[15] = 4; arrItems1[16] = "Keyboard"; arrItemsGrp1[16] = 4; arrItems1[17] = "Percussion"; arrItemsGrp1[17] = 4; arrItems1[20] = "Classical"; arrItemsGrp1[20] = 6; arrItems1[21] = "Contempory"; arrItemsGrp1[21] = 6; var arrItems2 = new Array(); var arrItemsGrp2 = new Array(); arrItems2[25] = "Violin"; arrItemsGrp2[25] = 12; arrItems2[26] = "Viola"; arrItemsGrp2[26] = 12; arrItems2[27] = "Cello"; arrItemsGrp2[27] = 12; arrItems2[28] = "Double Bass"; arrItemsGrp2[28] = 12; arrItems2[31] = "Flute"; arrItemsGrp2[31] = 13; arrItems2[32] = "Clarinet"; arrItemsGrp2[32] = 13; arrItems2[33] = "Piccolo"; arrItemsGrp2[33] = 13; arrItems2[34] = "Oboe"; arrItemsGrp2[34] = 13; arrItems2[35] = "Saxaphone"; arrItemsGrp2[35] = 13; arrItems2[37] = "Bassoon"; arrItemsGrp2[37] = 13; arrItems2[38] = "Recorder"; arrItemsGrp2[38] = 13; arrItems2[41] = "Trumpet"; arrItemsGrp2[41] = 14; arrItems2[42] = "Trombone"; arrItemsGrp2[42] = 14; arrItems2[43] = "Tuba"; arrItemsGrp2[43] = 14; arrItems2[44] = "French Horn"; arrItemsGrp2[44] = 14; arrItems2[45] = "Euphonium"; arrItemsGrp2[45] = 14; arrItems2[46] = "Flugelhorn"; arrItemsGrp2[46] = 14; arrItems2[51] = "Classic Guitar"; arrItemsGrp2[51] = 15; arrItems2[52] = "Electric Guitar"; arrItemsGrp2[52] = 15; arrItems2[53] = "Bass Guitar"; arrItemsGrp2[53] = 15; arrItems2[55] = "Jazz Singer"; arrItemsGrp2[55] = 21; arrItems2[56] = "Musical Theatre"; arrItemsGrp2[56] = 21; arrItems2[57] = "Pop Singer"; arrItemsGrp2[57] = 21; arrItems2[60] = "Soprano"; arrItemsGrp2[60] = 20; arrItems2[61] = "Mezzo-Soprano"; arrItemsGrp2[61] = 20; arrItems2[62] = "Contralto"; arrItemsGrp2[62] = 20; arrItems2[63] = "Tenor"; arrItemsGrp2[63] = 20; arrItems2[64] = "Baritone"; arrItemsGrp2[64] = 20; arrItems2[65] = "Bass Baritone"; arrItemsGrp2[65] = 20; arrItems2[66] = "Bass"; arrItemsGrp2[66] = 20; 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; if (control.name == "type1") { // Empty the third drop down box of any choices for (var q=form.type3.options.length;q>=0;q--) form.type3.options[q] =null; } // ADD Default Choice - in case there are no values myEle=document.createElement("option"); theText=document.createTextNode("All Specialities"); 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.value = x ; myEle.setAttribute("value",x); // myEle.text = ItemArray[x] ; var txt = document.createTextNode(ItemArray[x]); myEle.appendChild(txt) // controlToPopulate.add(myEle) ; controlToPopulate.appendChild(myEle) } } }




Bookmarks