-
Simple form question
I have a two drop down menus where you can select two different variables, type of fruit and a utensil. I would then like to take those variables and add them to a string for use as an URL. Here's where I am so far...
PHP Code:
<form id="form1" name="form1" action="" method="get">
<strong>Select a fruit:<br /></strong>
<select name="fruitSelection" class="fruit_dd">
<option value="">Select...</option>
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="orange">Orange</option>
</select>
<select name="utensilSelection" class="utensil_dd">
<option value="">Select...</option>
<option value="fork">Fork</option>
<option value="spoon">Spoon</option>
</select>
<input name="Button" type="submit" value="Submit" onClick="submitSelections()"/>
</form>
<script type="text/javascript">
function submitSelections() {
var newURL="http://www.sampleURL.com/index.html"
//How do I add the fruit and utensil to that URL?
}
Any help would be greatly appreciated!
-
Do you need to use JavaScript for a reason? If you do then sorry for this daft reply :p
<form id="form1" name="form1" action="http://www.sampleURL.com/index.html" method="get">
<strong>Select a fruit:<br /></strong>
<select name="fruitSelection" class="fruit_dd">
<option value="">Select...</option>
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="orange">Orange</option>
</select>
<select name="utensilSelection" class="utensil_dd">
<option value="">Select...</option>
<option value="fork">Fork</option>
<option value="spoon">Spoon</option>
</select>
<input name="Button" type="submit" value="Submit"/>
</form>
Would be how to do it with just plain simple HTML...
-
If you do need to use JavaScipt then the easiest way would be:
PHP Code:
<script type="text/javascript">
function submitSelections() {
var newURL="http://www.sampleURL.com/index.html"
newURL = newURL + "?fruitSelection="+ document.form1.fruitSelection.value +"&utensilSelection="+ document.form1.utensilSelection.value
alert ( newURL );
}
</script>
<form id="form1" name="form1" action="" method="get">
<strong>Select a fruit:<br /></strong>
<select name="fruitSelection" class="fruit_dd">
<option value="">Select...</option>
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="orange">Orange</option>
</select>
<select name="utensilSelection" class="utensil_dd">
<option value="">Select...</option>
<option value="fork">Fork</option>
<option value="spoon">Spoon</option>
</select>
<input name="Button" type="submit" value="Submit" onClick="submitSelections()"/>
</form>