Need Help with form.

Discussion in 'JavaScript' started by SiteExpress, Nov 22, 2006.

  1. #1
    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();">
    Code (markup):
    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>
    Code (markup):
    Menu #2
        <select name="opttwo">
           <option value=" " selected="selected">Select a Subject First</option>
    </select>
    Code (markup):
    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');
    }
    }
    Code (markup):
    Any help is greatly appreciated!
     
    SiteExpress, Nov 22, 2006 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    There's no onload attribute for forms.
     
    nico_swd, Nov 22, 2006 IP
  3. SiteExpress

    SiteExpress Well-Known Member

    Messages:
    1,355
    Likes Received:
    153
    Best Answers:
    0
    Trophy Points:
    155
    #3
    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?
     
    SiteExpress, Nov 22, 2006 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    
    <form action="your-page.php" method="post">
    
    [... your form stuff here]
    
    <input type="submit" value="Submit" />
    </form>
    
    HTML:
     
    nico_swd, Nov 22, 2006 IP
  5. weknowtheworld

    weknowtheworld Guest

    Messages:
    306
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The below code should work:

    <form action="your-page.php" method="post">
    [... your <select> </select> here....]
    <input type="submit" value="Go" />
    </form>
     
    weknowtheworld, Nov 30, 2006 IP