PDA

View Full Version : Forms etc


dmdb1423
11-29-2002, 12:12 AM
Ok this might sound like a really easy question to some people but I'm pretty new to Javascript.
I'm trying to create a script that when an option is selected in a drop down menu it changes the action of the form. If I enter a the action for the form as

<FORM action='action();'>

then that will call up the script but how do I get that script to check the value of the drop down box.:rolleyes:

whammy
11-29-2002, 03:21 AM
What are you trying to do?

If you're just trying to go to a different page depending on what's selected in a dropdown (just guessing here), it's much easier than that:

<form id="foobar" action="javascript://">
<select name="blah" onchange="window.location=this.options[this.selectedIndex].value">
<option value="http://www.yahoo.com">Yahoo!</option>
<option value="http://www.google.com">Google</option>
</select>
</form>

;)

If that's not what you're trying to do, please explain in a bit more detail. :)

glenngv
11-29-2002, 08:37 AM
maybe this:

<form id="foobar" action="page1.asp" method="post">
<select name="blah" onchange="this.form.action=this.options[this.selectedIndex].value">
<option value="page1.asp">Page 1</option>
<option value="page2.asp">Page 2</option>
<option value="page3.asp">Page 3</option>
</select>
<input type="submit" value="Submit">
</form>

dmdb1423
11-29-2002, 11:45 PM
The form consists of the drop down menu, a text field and the submit button. Depending on what option the user selects the text in the text field is posted to a different part of the site.
Any ideas...?

Thanks a lot for helping btw!

Duncan

chrismiceli
11-30-2002, 12:36 AM
<script type="text/javascript">
function chngaction() {
document.myForm.action = document.myForm.box[document.myForm.box.selectedIndex].value;
}
</script>
<form name="myForm" action="whatever">
<select name="box" onChange="chngaction()">
<option value="whatever0">hi</option>
<option value="whatever1">Hi again</option>
</select>
<input type="text" value="" name="txtfield">
<input type="submit">
</form>

in this code you are assigning the action by the value of the selected dropbox.

dmdb1423
11-30-2002, 10:57 AM
Thanks a lot! That works really well...:)