PDA

View Full Version : Passing Form Field to URL



littleredhairedgirl
08-13-2009, 01:06 PM
I'm trying to get the results from a form to append onto a URL.
An example would be to ask a couple of questions and use the answer to build a simple search query:
http://www.google.com/cse?cx=006572928691923562538:bbczg_etsxq&q=red+medium+thick


<HTML>
<HEAD>
<SCRIPT type="text/javascript">
function goToPage(results)
{
var initial = "http://www.google.com/cse?cx=006572928691923562538:bbczg_etsxq&q=";
var extension = "&sa=Search";
results = results+element_2_2+element_2_3
window.location(initial+results+extension);
}
</SCRIPT>

<BASE HREF="http://www.google.com/cse?cx=006572928691923562538:bbczg_etsxq">
</HEAD>

<BODY>
<P>
<FORM name="questions" action="#">

<INPUT type="text" name="results" value="" onSubmit="goToPage(this.value)">
<br>
<label class="description" for="element_2">Question 1 </label>

<input id="element_2_1" name="element_2" class="element radio" type="radio" value="1" />
<label class="choice" for="element_2_1">Small</label>
<input id="element_2_2" name="element_2" class="element radio" type="radio" value="2" />
<label class="choice" for="element_2_2">Medium</label>
<input id="element_2_3" name="element_2" class="element radio" type="radio" value="3" />
<label class="choice" for="element_2_3">Large</label>


<br>
<label class="description" for="element_3">Question 2 </label>

<input id="element_3_1" name="element_3" class="element radio" type="radio" value="1" />
<label class="choice" for="element_3_1">Thin</label>
<input id="element_3_2" name="element_3" class="element radio" type="radio" value="2" />
<label class="choice" for="element_3_2">Average</label>
<input id="element_3_3" name="element_3" class="element radio" type="radio" value="3" />
<label class="choice" for="element_3_3">Thick</label>


<INPUT type="submit" value="GO">
</FORM>
</BODY></HTML>