/    Sign up×
Community /Pin to ProfileBookmark

Simple Script, Dynamic Drop down not populating.

For some reason my second drop down list is not populating anymore after selecting the first one. I added a default drop-down, and that one is always the one being populated no matter my selection in the first. I’m semi-new to javascript, 90% of my scripting is PHP, so I’m guessing its an error in the way I have it set up (I get PHP and JS syntax confused alot). Just wondering if someone could take a gander and see what I’m missing here.

The Dropdown Menu’s:

[code=html]
<label>Location:</label></td>
<td> <!–document.fileform.location.options–>
<select id=”location” name=”location” size=”1″ onChange=”setOptions(this.options[this.selectedIndex].value);”>
<option value=” “>–Select Page–</option>
<option value=”1″>&nbsp;Documentation&nbsp;&nbsp;</option>
<option value=”2″>&nbsp;Regulatory&nbsp;&nbsp;</option>
<option value=”3″>&nbsp;Meetings&nbsp;&nbsp;</option>
<option value=”4″>&nbsp;Financial&nbsp;&nbsp;</option>
<option value=”5”>&nbsp;Management&nbsp;&nbsp;</option>
</select></td>
</tr>

<!–SECTION SELECT (dynamic, see javascript)–>

<tr>
<td>&nbsp;</td>
<td>
<select id=”section” name=”section” size=”1″>
<option value=” ” >–Choose Page First—</option>
</select>
</td>
</tr>
[/code]

For some reason the following function always thinks that form has a different value then any of the ones I have predefined in the function.

[code]
function setOptions(chosen)
{
var documentation=new Array ()
documentation[0] = ” Specifications “;
documentation[1] = ” Technical References “;
documentation[2] = ” R&D Specifications “;

var regulatory=new Array ()
regulatory[0] = ” Standards and Procedures “;
regulatory[1] = ” References “;
regulatory[2] = ” Correspondence “;
regulatory[3] = ” Problem Tracking “;

var meetings=new Array ()
meetings[0] = ” General “;
meetings[1] = ” Development Team “;
meetings[2] = ” Program Status “;
meetings[3] = ” Design Review “;

var financial=new Array ()
financial[0] = ” Reports and Agreements “;
financial[1] = ” Data “;

var management=new Array()
management[0] = ” General “;

var section = document.fileform.section;
//end vars

section.options.length = 0;

switch (section)
{

case ((chosen == ” “) || (!chosen) || (chosen = “”)):

section.options[section.options.length] = new Option(‘–Choose Page First–‘, ‘ ‘);
break;

case (chosen == “1”):

for (i=0;i<3;i++)
{
section.options[section.options.length] = new Option(documentation[i], i);
}
break;

case (chosen == “2”):

for (i=0;i<4;i++)
{
section.options[section.options.length] = new Option(regulatory[i], i);
}
break;

case (chosen == “3” ):

for (i=0;i<4;i++)
{
section.options[section.options.length] = new Option(meetings[i], i);
}
break

case (chosen == “4”):

for (i=0;i<2;i++)
{
section.options[section.options.length] = new Option(financial[i], i);
}
break;

case (chosen == “5”):

section.options[section.options.length] = new Option(‘General’, ‘0’);
break;

default:
section.options[section.options.length] = new Option(‘–Default Case–‘, ‘ ‘);
break;
//it always comes up with default
}

}
//end function
[/code]

Thanks for looking into it.

–T.J.–

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@TJ111authorJul 02.2007 — Firebug is telling me "Chosen is not defined", but is giving me accurate values for both "document.fileform.location.options[document.fileform.location.selectedIndex].value"

and "document.fileform.section.options[document.fileform.section.selectedIndex].value"

. That means that "chosen" isn't properly being assigned a value.
×

Success!

Help @TJ111 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.16,
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,
)...