Select menus and forms

Hello!

I have a webpage with 3 different forms, each of which “shows itself” (via javascript) under different circumstances. Information is then submitted to my database via php. There’s some information in common to all 3 forms that I’d like to pull off from a select menu and then submit as part of the form; instead of writing my select menu 3 times (which is actually much longer than the one provided), I’m wondering if I can use javascript to pull off the selected response in combination with some sort of “hidden” field on my form to make it work so that when I submit the form, the selected pull-down menu item goes along with the form in question. As an example, using “quasi-code”:

<select name="chapter" id="chapter">
  <option value="Linear_Functions">Linear Functions</option>
  <option value="Quadratic_functions">Quadratic Functions</option>
</select>  //whichever is chosen here I'd like to submit with the form that the person responds to below

<form1 multiple choice type question input stuff>
<form2 free response type question input stuff>
<form3 numeric type question input stuff>  //only one of the 3 forms will be seen by the user.

Any help would be appreciated.

Thank you,

Eric

Place a hidden value within each form, so that when the form is updated it can update that hidden value when submitted.


<input type="hidden" name="chapter">


function updateForm() {
    var select = document.getElementById('select');
    this.chapter.value = select.options[select.selectedIndex].value;
}
var form1 = document.getElementById('form1'),
    form2 = document.getElementById('form2'),
    form3 = document.getElementById('form3');
form1.onsubmit = updateForm;
form2.onsubmit = updateForm;
form3.onsubmit = updateForm;

Very cool! Thanks so much…

-Eric