|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am creating a wizard using dependant drop downs and the 6 drop downs work perfectly.
Wish one: I would like the final choice to appear as text instead of another drop down. Wish two: If the user goes back and changes a selection, right now it only resets the one below it. I would like for it to reset all dependant drop downs instead. I am worried that they won't realize that the last one is not automatically updating. Example: Select all then go back and change selection #2. The final result is still there but it is no longer correct based on the new selection. I thought maybe if I had a button tied to the sixth choice, I could make the first 5 required before submit and resolve both issues, but I can't figure out how to code it. Can anyone help? See my code below (in reality I have hundreds of selections). In this example, select the first choice in each box to populate all drop downs. <HEAD> <script type="text/javascript"> <!-- var arrItems1 = new Array(); var arrItemsGrp1 = new Array(); arrItems1[1] = "Selection 1"; arrItemsGrp1[1] = 1; arrItems1[2] = "Selection 2"; arrItemsGrp1[2] = 1; arrItems1[3] = "Selection 3"; arrItemsGrp1[3] = 1; var arrItems2 = new Array(); var arrItemsGrp2 = new Array(); arrItems2[12] = "Selection 1"; arrItemsGrp2[12] = 1 arrItems2[13] = "Selection 2"; arrItemsGrp2[13] = 1 arrItems2[14] = "Selection 3"; arrItemsGrp2[14] = 1 arrItems2[15] = "Selection 4"; arrItemsGrp2[15] = 1 arrItems2[16] = "Selection 5"; arrItemsGrp2[16] = 1 arrItems2[17] = "Selection 6"; arrItemsGrp2[17] = 1 var arrItems3 = new Array(); var arrItemsGrp3 = new Array(); arrItems3[42] = "Selection 1"; arrItemsGrp3[42] = 12 arrItems3[43] = "Selection 2"; arrItemsGrp3[43] = 12 arrItems3[44] = "Selection 3"; arrItemsGrp3[44] = 12 var arrItems4 = new Array(); var arrItemsGrp4 = new Array(); arrItems4[133] = "Selection 1"; arrItemsGrp4[133] = 42 var arrItems5 = new Array(); var arrItemsGrp5 = new Array(); arrItems5[244] = "Selection 1"; arrItemsGrp5[244] = 133 arrItems5[245] = "Selection 2"; arrItemsGrp5[245] = 133 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 == "firstChoice") { // Empty the third drop down box of any choices for (var q=form.thirdChoice.options.length;q>=0;q--) form.thirdChoice.options[q] = null; } // ADD Default Choice - in case there are no values myEle = document.createElement("option") ; myEle.value = 0 ; myEle.text = "[SELECT]" ; // controlToPopulate.add(myEle) ; 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) } } } 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 == "firstChoice") { // Empty the third drop down box of any choices for (var q=form.thirdChoice.options.length;q>=0;q--) form.thirdChoice.options[q] = null; } // ADD Default Choice - in case there are no values myEle=document.createElement("option"); theText=document.createTextNode("[SELECT]"); 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) } } } // --> </script> </HEAD> <BODY> <form name=form> <div align="center"> <table border="2" width="317" id="table1" bordercolor="#64367C"> <tr> <td width="305" align="left"> <font face="Courier"><b>Choice 1:</b> <font size="3" face="Courier"> <select id="firstChoice" name="firstChoice" onchange="selectChange(this, form.secondChoice, arrItems1, arrItemsGrp1);"> <option value="0" selected>[SELECT]</option> <option value="1">Selection 1</option> <option value="2">Selection 2</option> <option value="3">Selection 3</option> </select></font></font></td> <tr> <td width="305" align="left"> <font face="Courier"><b>Choice 2: </b> <font size="3" face="Courier"> <select id="secondChoice" name="secondChoice" onchange="selectChange(this, form.thirdChoice, arrItems2, arrItemsGrp2);" size="1"></select></font></font></td> </tr> <tr> <td width="305" align="left"> <font face="Courier"><b>Choice 3: </b> <font size="3" face="Courier"> <select id="thirdChoice" name="thirdChoice" onchange="selectChange(this, form.fourthChoice, arrItems3, arrItemsGrp3);" size="1"></select></font></font></td> </tr> <tr> <td width="305" align="left"> <font face="Courier"><b>Choice 4: </b> <font size="3" face="Courier"> <select id="fourthChoice" name="fourthChoice" onchange="selectChange(this, form.fifthChoice, arrItems4, arrItemsGrp4);" size="1"></select></font></font></td> </tr> <tr> <td width="305" align="left"> <font face="Courier"><b>Choice 5:</b> <font size="3" face="Courier"> <select id="fifthChoice" name="fifthChoice" onchange="selectChange(this, form.sixthChoice, arrItems5, arrItemsGrp5);" size="1"></select></font></font></td> </tr> <tr> <td width="305" align="left"> <p><b><font face="Courier"> Answer: </font></b> <font size="3" face="Courier"> <select id="sixthChoice" name="sixthChoice" size="1"></select> </font></p></td> </tr> </table> </div> </form> |
|
#2
|
|||
|
|||
|
Quote:
wish 2 Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<HEAD>
<script type="text/javascript">
<!--
var arrItems1 = new Array();
var arrItemsGrp1 = new Array();
arrItems1[1] = "Selection 1";
arrItemsGrp1[1] = 1;
arrItems1[2] = "Selection 2";
arrItemsGrp1[2] = 1;
arrItems1[3] = "Selection 3";
arrItemsGrp1[3] = 1;
var arrItems2 = new Array();
var arrItemsGrp2 = new Array();
arrItems2[12] = "Selection 1";
arrItemsGrp2[12] = 1
arrItems2[13] = "Selection 2";
arrItemsGrp2[13] = 1
arrItems2[14] = "Selection 3";
arrItemsGrp2[14] = 1
arrItems2[15] = "Selection 4";
arrItemsGrp2[15] = 1
arrItems2[16] = "Selection 5";
arrItemsGrp2[16] = 1
arrItems2[17] = "Selection 6";
arrItemsGrp2[17] = 1
var arrItems3 = new Array();
var arrItemsGrp3 = new Array();
arrItems3[42] = "Selection 1";
arrItemsGrp3[42] = 12
arrItems3[43] = "Selection 2";
arrItemsGrp3[43] = 12
arrItems3[44] = "Selection 3";
arrItemsGrp3[44] = 12
var arrItems4 = new Array();
var arrItemsGrp4 = new Array();
arrItems4[133] = "Selection 1";
arrItemsGrp4[133] = 42
var arrItems5 = new Array();
var arrItemsGrp5 = new Array();
arrItems5[244] = "Selection 1";
arrItemsGrp5[244] = 133
arrItems5[245] = "Selection 2";
arrItemsGrp5[245] = 133
function selectChange(control,nu){
var frm=control.form;
var sel=frm['Choice'+nu];
var iary=window['arrItems'+nu];
var gary=window['arrItemsGrp'+nu];
var cnt=1;
while (frm['Choice'+cnt]){
if (cnt>=nu){
while (frm['Choice'+cnt].firstChild){
frm['Choice'+cnt].removeChild(frm['Choice'+cnt].firstChild);
}
}
cnt++;
}
var myEle=document.createElement("option");
myEle.appendChild(document.createTextNode("[SELECT]"));
myEle.setAttribute("value","0");
sel.appendChild(myEle);
for (var x = 0 ; x < iary.length ; x++ ) {
if ( gary[x]==control.value ) {
myEle = document.createElement("option");
myEle.setAttribute("value",x);
myEle.appendChild(document.createTextNode(iary[x]));
sel.appendChild(myEle);
}
}
}
// -->
</script>
</HEAD>
<BODY>
<form name=form>
<div align="center">
<table border="2" width="317" id="table1" bordercolor="#64367C">
<tr>
<td width="305" align="left">
<font face="Courier"><b>Choice 1:</b> <font size="3" face="Courier">
<select id="Choice0" name="Choice0" onchange="selectChange(this, 1);">
<option value="0" selected>[SELECT]</option>
<option value="1">Selection 1</option>
<option value="2">Selection 2</option>
<option value="3">Selection 3</option>
</select></font></font></td>
<tr>
<td width="305" align="left">
<font face="Courier"><b>Choice 2: </b> <font size="3" face="Courier">
<select id="secondChoice" name="Choice1" onchange="selectChange(this, 2);" size="1"></select></font></font></td>
</tr>
<tr>
<td width="305" align="left">
<font face="Courier"><b>Choice 3: </b> <font size="3" face="Courier">
<select id="thirdChoice" name="Choice2" onchange="selectChange(this, 3);" size="1"></select></font></font></td>
</tr>
<tr>
<td width="305" align="left">
<font face="Courier"><b>Choice 4: </b> <font size="3" face="Courier">
<select id="fourthChoice" name="Choice3" onchange="selectChange(this, 4);" size="1"></select></font></font></td>
</tr>
<tr>
<td width="305" align="left">
<font face="Courier"><b>Choice 5:</b> <font size="3" face="Courier">
<select id="fifthChoice" name="Choice4" onchange="selectChange(this, 5);" size="1"></select></font></font></td>
</tr>
<tr>
<td width="305" align="left">
<p><b><font face="Courier"> Answer: </font></b>
<font size="3" face="Courier">
<select id="sixthChoice" name="Choice5" size="1"></select>
</font></p></td>
</tr>
</table>
</div>
</form>
Wish one: I would like the final choice to appear as text instead of another drop down.
<br />
<br />
Wish two: If the user goes back and changes a selection, right now it only resets the one below it. I would like for it to reset all dependant drop downs instead. I am worried that they won't realize that the last one is not automatically updating. Example: Select all then go back and change selection #2. The final result is still there but it is no longer correct based on the new selection.
<br />
<br />
</body>
</html>
__________________
Vic God loves you and will never love you less. http://www.vicsjavascripts.org.uk remove any spaces between java & script |
|
#3
|
|||
|
|||
|
Thank you! That was perfect!
To clarify wish one... Right now when you select from box five it populates box six. In my form they don't choose from box six because it is where the answers to their question should appear. So, I would like it to appear as text instead of in a drop down box. It would look like this: [Selection 1] [Selection 1] [Selection 1] [Selection 1] [Selection 1] Answer Selection 1 Selection 2 |
|
#4
|
|||
|
|||
|
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<HEAD>
<script type="text/javascript">
<!--
var arrItems1 = new Array();
var arrItemsGrp1 = new Array();
arrItems1[1] = "Selection 1";
arrItemsGrp1[1] = 1;
arrItems1[2] = "Selection 2";
arrItemsGrp1[2] = 1;
arrItems1[3] = "Selection 3";
arrItemsGrp1[3] = 1;
var arrItems2 = new Array();
var arrItemsGrp2 = new Array();
arrItems2[12] = "Selection 1";
arrItemsGrp2[12] = 1
arrItems2[13] = "Selection 2";
arrItemsGrp2[13] = 1
arrItems2[14] = "Selection 3";
arrItemsGrp2[14] = 1
arrItems2[15] = "Selection 4";
arrItemsGrp2[15] = 1
arrItems2[16] = "Selection 5";
arrItemsGrp2[16] = 1
arrItems2[17] = "Selection 6";
arrItemsGrp2[17] = 1
var arrItems3 = new Array();
var arrItemsGrp3 = new Array();
arrItems3[42] = "Selection 1";
arrItemsGrp3[42] = 12
arrItems3[43] = "Selection 2";
arrItemsGrp3[43] = 12
arrItems3[44] = "Selection 3";
arrItemsGrp3[44] = 12
var arrItems4 = new Array();
var arrItemsGrp4 = new Array();
arrItems4[133] = "Selection 1";
arrItemsGrp4[133] = 42
var arrItems5 = new Array();
var arrItemsGrp5 = new Array();
arrItems5[244] = "Selection 1";
arrItemsGrp5[244] = 133
arrItems5[245] = "Selection 2";
arrItemsGrp5[245] = 133
function selectChange(control,nu){
var frm=control.form;
var sel=frm['Choice'+nu];
var iary=window['arrItems'+nu];
var gary=window['arrItemsGrp'+nu];
var cnt=1;
while (frm['Choice'+cnt]){
if (cnt>=nu){
while (frm['Choice'+cnt].firstChild){
frm['Choice'+cnt].removeChild(frm['Choice'+cnt].firstChild);
}
}
cnt++;
}
var myEle=document.createElement("option");
myEle.appendChild(document.createTextNode("[SELECT]"));
myEle.setAttribute("value","0");
sel.appendChild(myEle);
for (var x = 0 ; x < iary.length ; x++ ) {
if ( gary[x]==control.value ) {
myEle = document.createElement("option");
myEle.setAttribute("value",x);
myEle.appendChild(document.createTextNode(iary[x]));
sel.appendChild(myEle);
}
}
}
function HTMLChange(control,nu){
var frm=control.form;
var iary=window['arrItems'+nu];
var gary=window['arrItemsGrp'+nu];
for (var txt='',x = 0 ; x < iary.length ; x++ ) {
if ( gary[x]==control.value ) {
txt+=iary[x]+'<BR>';
}
}
document.getElementById('Choice'+nu).innerHTML=txt;
}
// -->
</script>
</HEAD>
<BODY>
<form name=form>
<div align="center">
<table border="2" width="317" id="table1" bordercolor="#64367C">
<tr>
<td width="305" align="left">
<font face="Courier"><b>Choice 1:</b> <font size="3" face="Courier">
<select id="Choice0" name="Choice0" onchange="selectChange(this, 1);">
<option value="0" selected>[SELECT]</option>
<option value="1">Selection 1</option>
<option value="2">Selection 2</option>
<option value="3">Selection 3</option>
</select></font></font></td>
<tr>
<td width="305" align="left">
<font face="Courier"><b>Choice 2: </b> <font size="3" face="Courier">
<select id="secondChoice" name="Choice1" onchange="selectChange(this, 2);" size="1"></select></font></font></td>
</tr>
<tr>
<td width="305" align="left">
<font face="Courier"><b>Choice 3: </b> <font size="3" face="Courier">
<select id="thirdChoice" name="Choice2" onchange="selectChange(this, 3);" size="1"></select></font></font></td>
</tr>
<tr>
<td width="305" align="left">
<font face="Courier"><b>Choice 4: </b> <font size="3" face="Courier">
<select id="fourthChoice" name="Choice3" onchange="selectChange(this, 4);" size="1"></select></font></font></td>
</tr>
<tr>
<td width="305" align="left">
<font face="Courier"><b>Choice 5:</b> <font size="3" face="Courier">
<select id="fifthChoice" name="Choice4" onchange="HTMLChange(this, 5);" size="1"></select></font></font></td>
</tr>
<tr>
<td width="305" align="left">
<p><b><font face="Courier"> Answer: </font></b>
<font size="3" face="Courier">
<div id="Choice5"></div>
</font></p></td>
</tr>
</table>
</div>
</form>
Wish one: I would like the final choice to appear as text instead of another drop down.
<br />
<br />
Wish two: If the user goes back and changes a selection, right now it only resets the one below it. I would like for it to reset all dependant drop downs instead. I am worried that they won't realize that the last one is not automatically updating. Example: Select all then go back and change selection #2. The final result is still there but it is no longer correct based on the new selection.
<br />
<br />
</body>
</html>
__________________
Vic God loves you and will never love you less. http://www.vicsjavascripts.org.uk remove any spaces between java & script |
|
#5
|
|||
|
|||
|
Thank you so much! Unfortunately the choice 6 is not refreshing now when you change the other drop-downs. Is there any way to fix that?
|
|
#6
|
|||
|
|||
|
Dependant Selections to Textbox
Thanks so much for all of your help! The drop downs etc. are working perfectly.
Is there a way to collect the selections chosen in the text area I have added, as a second onChange event? I am copying the new code so you can see the text area that I want to be the target. <html> <head> <HEAD> <script type="text/javascript"> <!-- var arrItems1 = new Array(); var arrItemsGrp1 = new Array(); arrItems1[1] = "Selection 1"; arrItemsGrp1[1] = 1; arrItems1[2] = "Selection 2"; arrItemsGrp1[2] = 1; arrItems1[3] = "Selection 3"; arrItemsGrp1[3] = 1; var arrItems2 = new Array(); var arrItemsGrp2 = new Array(); arrItems2[12] = "Selection 1"; arrItemsGrp2[12] = 1 arrItems2[13] = "Selection 2"; arrItemsGrp2[13] = 1 arrItems2[14] = "Selection 3"; arrItemsGrp2[14] = 1 arrItems2[15] = "Selection 4"; arrItemsGrp2[15] = 1 arrItems2[16] = "Selection 5"; arrItemsGrp2[16] = 1 arrItems2[17] = "Selection 6"; arrItemsGrp2[17] = 1 var arrItems3 = new Array(); var arrItemsGrp3 = new Array(); arrItems3[42] = "Selection 1"; arrItemsGrp3[42] = 12 arrItems3[43] = "Selection 2"; arrItemsGrp3[43] = 12 arrItems3[44] = "Selection 3"; arrItemsGrp3[44] = 12 var arrItems4 = new Array(); var arrItemsGrp4 = new Array(); arrItems4[133] = "Selection 1"; arrItemsGrp4[133] = 42 var arrItems5 = new Array(); var arrItemsGrp5 = new Array(); arrItems5[244] = "Selection 1"; arrItemsGrp5[244] = 133 arrItems5[245] = "Selection 2"; arrItemsGrp5[245] = 133 function selectChange(control,nu){ var frm=control.form; var sel=frm['Choice'+nu]; var iary=window['arrItems'+nu]; var gary=window['arrItemsGrp'+nu]; var cnt=1; while (frm['Choice'+cnt]){ if (cnt>=nu){ while (frm['Choice'+cnt].firstChild){ frm['Choice'+cnt].removeChild(frm['Choice'+cnt].firstChild); } } cnt++; } var myEle=document.createElement("option"); myEle.appendChild(document.createTextNode("[SELECT ONE]")); myEle.setAttribute("value","0"); sel.appendChild(myEle); for (var x = 0 ; x < iary.length ; x++ ) { if ( gary[x]==control.value ) { myEle = document.createElement("option"); myEle.setAttribute("value",x); myEle.appendChild(document.createTextNode(iary[x])); sel.appendChild(myEle); } } } // --> </script> <script language='Javascript'> function doact(d) { var doc = eval("document.form."+d); cp = doc.createTextRange(); doc.focus(); doc.select(); cp.execCommand("Copy"); } function FP_popUpMsg(msg) {//v1.0 alert(msg); } </script> </HEAD> <BODY> <form name=form> <div align="center"> <table border="2" width="790" id="table1" bordercolor="#64367C"> <tr> <td width="778" align="left" colspan="2"> </td> <tr> <td width="305" align="left"> <font size="2" face="MS Sans Serif"> Choice 1:<font size="2" face="MS Sans Serif"> <select id="Choice0" name="Choice0" onchange="selectChange(this, 1);"> <option value="0" selected>[SELECT]</option> <option value="1">Selection 1</option> <option value="2">Selection 2</option> <option value="3">Selection 3</option> </select></font></font></td> <td width="225" align="center" onclick="FP_popUpMsg('More Info')"> <font face="MS Sans Serif" size="2" color="#FF0000">*</font><font face="MS Sans Serif" size="2" color="#0000FF"> <u> Tell me more</u></font></td> <tr> <td width="547" align="left"> <font size="2" face="MS Sans Serif"> Code 2: <select id="secondChoice" name="Choice1" onchange="selectChange(this, 2); "></select></font></td> <td width="225" align="center" rowspan="4"> <TEXTAREA name="text1" cols="25" rows="5"> Selections will populate here. </TEXTAREA><input onclick="doact('text1')" type="button" value="Copy"> </td> </tr> <tr> <td width="547" align="left"> <font size="2" face="MS Sans Serif"> Code 3: <select id="thirdChoice" name="Choice2" onchange="selectChange(this, 3);"></select></font></td> </tr> <tr> <td width="547" align="left"> <font size="2" face="MS Sans Serif"> Code 4: <select id="fourthChoice" name="Choice3" onchange="selectChange(this, 4);"></select></font></td> </tr> <tr> <td width="547" align="left"> <font face="MS Sans Serif" size="2"> Code 5: </font> <font size="3" face="Courier"> <select id="fifthChoice" name="Choice4" onchange="selectChange(this, 5);" size="1"></select></font></td> </tr> <tr> <td width="547" align="left"> <p><font face="MS Sans Serif" size="2"> Answer: </font> <font size="3" face="Courier"> <select id="sixthChoice" name="Choice5" onChange="alert('Reminder')" size="1"></select> </font></p></td> <td width="225" align="center"> <font size="2" face="MS Sans Serif"> <a target="_blank" href="reference.htm">Show the Full Spreadsheet</a></a></font></td> </tr> <tr> <td width="778" align="left" colspan="2"> </td> </tr> </table> </div> </form> </body> </html> |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|