/    Sign up×
Community /Pin to ProfileBookmark

dynamic menu, works for 2, need for 3-4

okay, this snippit works to fill in the contents of box 2 when you select info from box 1… what i need is a code that will do this for 3-4 boxes, so i fill in 1, it gives info for 2, then i select 2, and it fills in the info for 3, etc…

any ideas?

[code=php]
<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin

classes = new Array(
new Array(
new Array(“Blazer”, “Blazer”),
new Array(“Corvette”, “Corvette”)
),
new Array(
new Array(“Dakota”, “Dakota”),
new Array(“Ram 1500”, “Ram 1500”)
),
new Array(
new Array(“Escort”, “Escort”),
new Array(“F-150”, “F-150”),
new Array(“F-250”, “F-250”),
new Array(“Mustang Cobra”, “Mustang Cobra”)
),
new Array(
new Array(“Altima”, “Altima”),
new Array(“Pathfinder”, “Pathfinder”)
)
);

function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;

// empty existing items
for (i = selectCtrl.options.length; i >= 0; i–) {
selectCtrl.options[i] = null;
}

prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
} else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {

// add new items
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[i][0]);
if (itemArray[i][1] != null) {
selectCtrl.options[j].value = itemArray[i][1];
}
j++;
}

// select first item (prompt) for sub list
selectCtrl.options[0].selected = true;

}
}

// End –>
</script>
<table>
<form name=”main” action=”manage_item_add.php?action=add” method=”post” enctype=”multipart/form-data”>
<tr>
<td valign=”center” align=”right” colspan=”2″> </td>
</tr>
<tr>
<td align=”right”>Make: &nbsp; </td>
<td>
<SELECT style=”width: 180px;” NAME=”Race” onChange=”fillSelectFromArray(this.form.Classes, ((this.selectedIndex == -1) ? null : classes[this.selectedIndex-1]));”>
<option value=”-1″>Select Make</option>
<option value=”Chevrolet”>Chevrolet</option>
<option value=”Dodge”>Dodge</option>
<option value=”Ford”>Ford</option>
<option value=”Nissan”>Nissan</option> </td>
</tr>
<tr>
<td align=”right”><br />Model: &nbsp; </td>
<td><br /><SELECT NAME=”Classes” style=”width: 180px;”>
<OPTION value=””>Select Model</OPTION>
</SELECT>
</td>
</tr>
</form>
</table>
[/code]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @kender spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...