Simple JavaScript will do the trick. The parts you need to understand:
1. the "return" keyword, and how it is used with a submit button to either perform or cancel a form submission (that is to say, if you really meant "submit" button in your question, as a normal button can do the same thing)
2. the "id" attribute... you'll need to give each HTML element a unique id, so that it can be referenced via JavaScript
3. the "document.getElementById()" method
4. how selects are referenced, their attributes and methods.
If you have a textbox and a select element in your form:
[html]<form>
<input id="myText"/><br/>
<select id="mySelect"/>
<option value="Volvo"/>Volvo
<option value="Saab"/>Saab
<option value="Fiat"/>Fiat
<option value="Audi"/>Audi
</select>
</form> [/html]
Then you could add an "onChange" handler to the select:
[html]<form>
<input id="myText"/><br/>
<select id="mySelect" onChange="javascript:doSelect(this);"/>
<option value="Volvo"/>Volvo
<option value="Saab"/>Saab
<option value="Fiat"/>Fiat
<option value="Audi"/>Audi
</select>
</form> [/html]
The "doSelect()" function might look like this:
[html]function mySelect(x)
{
document.getElementById("myText").value = x.options[x.selectedIndex].value;
}[/html]
Each time the user selects a new option in the select, the value of the selected option is copied to the textbox. The same technique could be done for hidden elements, and of course the function could be wired to the submit event of the form instead of the change event of the select.
Reputation Points: 227
Solved Threads: 37
Made Her Cry
Offline 1,697 posts
since Dec 2004