Home Loan - Free Advertising - Pacotes Porto Seguro - Cheap Car Insurance - Mortgage Calculator

PDA

View Full Version : Need Help with form.


SiteExpress
Nov 22nd 2006, 11:10 am
I am new to php and MySQL, and recently needed to use a bit of JS to do a form dynamic lselect menu.

I now have the menu working as needed, but the one last thing I need help with. After the selections are done, I need a "Go" button to send the user to a corrosponding URL, depending on their combo of selections.

Here is my code.

<form name="myform" onload="SetForm();">Menu #1
<select name="optone" onchange="setOptions(document.myform.optone.options[document.myform.optone.selectedIndex].value);">
<option selected="selected">--- Select Subject ---</option>
<option value="1">Business and MBA Degrees</option>
<option value="2">Computer Science &amp; IT</option>
<option value="3">Criminal Justice</option>
<option value="4">Education Degrees</option>
<option value="5">Human Services Degrees</option>
<option value="6">Science &amp; Engineering</option>
</select>Menu #2
<select name="opttwo">
<option value=" " selected="selected">Select a Subject First</option>
</select>My js code
function setOptions(chosen) {
var selbox = document.myform.opttwo;

selbox.options.length = 0;
if (chosen == " ") {
selbox.options[selbox.options.length] = new Option('Please select one of the options above first',' ');

}
if (chosen == "1") {
selbox.options[selbox.options.length] = new Option('Accounting','accounting');
selbox.options[selbox.options.length] = new Option('Applied Management','applied-management');
selbox.options[selbox.options.length] = new Option('Business Degrees','business-degrees');
selbox.options[selbox.options.length] = new Option('Business Management','business-management');
}
if (chosen == "2") {
selbox.options[selbox.options.length] = new Option('Compueter Science','compueter-science');
selbox.options[selbox.options.length] = new Option('Computer Engineering','computer-engineering');
selbox.options[selbox.options.length] = new Option('Computer Security','computer-security');
selbox.options[selbox.options.length] = new Option('Computer Database','computer-database');
}
if (chosen == "3") {
selbox.options[selbox.options.length] = new Option('Criminal Justice','criminal-justice');
selbox.options[selbox.options.length] = new Option('Forensic Science','forensic-science');
selbox.options[selbox.options.length] = new Option('Homeland Security','homeland-security');
}
if (chosen == "4") {
selbox.options[selbox.options.length] = new Option('Master of Education','master-of-education');
selbox.options[selbox.options.length] = new Option('M.A. in Teaching','ma-in-Teaching');
selbox.options[selbox.options.length] = new Option('Educational Leadership','educational-leadership');
}
if (chosen == "5") {
selbox.options[selbox.options.length] = new Option('Counseling','counseling');
selbox.options[selbox.options.length] = new Option('Disaster Management','disaster-management');
selbox.options[selbox.options.length] = new Option('Healthcare Management','healthcare-management');
selbox.options[selbox.options.length] = new Option('Psychology','psychology');
}
if (chosen == "6") {
selbox.options[selbox.options.length] = new Option('Environmental Engineering','environmental-engineering');
selbox.options[selbox.options.length] = new Option('Engineering Management','engineering-management');
selbox.options[selbox.options.length] = new Option('General Engineering','general-engineering');
}
}Any help is greatly appreciated!

nico_swd
Nov 22nd 2006, 11:54 am
There's no onload attribute for forms.

SiteExpress
Nov 22nd 2006, 12:29 pm
I'm not sure what Onload would do anyway, but what I think I need is a go button with an onclick attribute that sends the user to a new page called (Whatever option two is).php

Any way to do this?

nico_swd
Nov 22nd 2006, 4:24 pm
<form action="your-page.php" method="post">

[... your form stuff here]

<input type="submit" value="Submit" />
</form>

weknowtheworld
Nov 30th 2006, 2:44 am
The below code should work:

<form action="your-page.php" method="post">
[... your <select> </select> here....]
<input type="submit" value="Go" />
</form>