/    Sign up×
Community /Pin to ProfileBookmark

Broken dynamic <select> menu

Ok, I’d been working on this code for awhile with BigMoosie’s help. It’s been rather unco-operative…

Basically, I have a <select> menu that changes based on the selection in the previous menu. When the user submits the form the values are e-mailed to me.

The script that changes the <select>

[code=php]
function ldMenu(mySubject, doKeep) {
var Indx=mySubject;
with (document.application.occ)
{
if (Indx==0)
{
options[0]=new Option(” – – Class – – “,””);
}
if (Indx==1)
{
options[0]=new Option(” – – Class – – “,””);
options[1]=new Option(“Druid”,”Druid”);
options[2]=new Option(“Hunter”,”Hunter”);
options[3]=new Option(“Preist”,”Preist”);
options[4]=new Option(“Rogue”,”Rogue”);
options[5]=new Option(“Warrior”,”Warrior”);
options.length=5;
}
if (Indx==2)
{
options[0]=new Option(” – – Class – – “,””);
options[1]=new Option(“Mage”,”Mage”);
options[2]=new Option(“Paladin”,”Paladin”);
options[3]=new Option(“Preist”,”Preist”);
options[4]=new Option(“Rogue”,”Rogue”);
options[5]=new Option(“Warrior”,”Warrior”);
options[6]=new Option(“Warlock”,”Warlock”);
options.length=7;
}
if (Indx==3)
{
options[0]=new Option(” – – Class – – “,””);
options[1]=new Option(“Hunter”,”Hunter”);
options[2]=new Option(“Paladin”,”Paladin”);
options[3]=new Option(“Preist”,”Preist”);
options[4]=new Option(“Rogue”,”Rogue”);
options[5]=new Option(“Warrior”,”Warrior”);
options.length=6;
}
if (Indx==4)
{
options[0]=new Option(” – – Class – – “,””);
options[1]=new Option(“Mage”,”Mage”);
options[2]=new Option(“Rogue”,”Rogue”);
options[3]=new Option(“Warlock”,”Warlock”);
options[4]=new Option(“Warrior”,”Warrior”);
options.length=5;
}
if (doKeep!=null) application.occ.options[doKeep].selected=true;
else application.occ.options[0].selected=true;

}

}
[/code]

The important/broken parts of the form

[code=php]
<form onsubmit=”storeinfo(); return true;” action=”apply.php” method=”POST” name=”application”>
<select name=”race” onChange=”ldMenu(this.selectedIndex);” size=”1″>
<option value =none selected=”selected”> – – Race – – </option>
<option value =”Night Elf”>Night Elf</option>
<option value =”Human”>Human</option>
<option value =”Dwarf”>Dwarf</option>
<option value =”Gnome”>Gnome</option>
</select>
<select name=”occ” size=”1″>
<option selected=”selected”> – – Class – – </option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
</select>
[/code]

Now, there are 2 problems.
1.) If someone makes a mistake they get an error page that indicates what field they left blank and are provided a link to go back to the form. All the options in the form are remembered, except they have to reselect their class. I’d like it to remember their class
2.) If you select Night Elf the last option, Warrior, wont display in the second <select> menu

Everything else about the script works right now and I’d be in hog heaven if I could get these last 2 bugs worked out

A live version of this is posted at the site, [url]http://www.kotguild.net/apply.php[/url] and if needed I have a zip of the page and all linked files that I’ll post.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@FangMay 17.2005 — 1.) Use php to display the page rather than a link 'back'

2.) options.length=[COLOR=Red]6[/COLOR];
Copy linkTweet thisAlerts:
@syrixauthorMay 17.2005 — Awesome, thanks! ...'cept I'm not sure what you mean/how to use php to display the page instead of a link back.
Copy linkTweet thisAlerts:
@FangMay 17.2005 — The page is displayed depending on which values are passed to itself.

You don't have seperate pages for the form, errors or validation, it is one page.

Using &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']?&gt;" method="post" id="myform"&gt; allows the page to call itself.

The values it passes are validated and placed in the form for re-displaying. See [URL=http://www.onlamp.com/pub/a/php/2004/08/26/PHPformhandling.html]this example[/URL]
×

Success!

Help @syrix 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...