Forum Moderators: open
I'm trying to create a form where by default it uses google to search one section of my site (using a hidden field) and then if you click a radio button it searches a different part of my site. I think this easy using Javascript and variables but i'm just not sure how. Please take a look at my code :
<form action="http://www.google.com/search" method="get" name="Form1">
<input type="text" maxLength=100 size="30" value="";" name='query' value="" alt="search"> <input alt="submit" type="submit" value="GOOGLE">
<input type="hidden" name="site" value="firstarea.mywebsite.com">
<input type="radio" id="secondary" name="site" value="secondarea.mywebsite.com"/>
<label for="secondary">SECONDARY AREA</label>
<input type="radio" id="third" name="site" value="thirdarea.mywebsite.com"/>
<label for="third">THIRD AREA</label>
<form action="http://www.google.com/search" method="get" name="Form1"><input type="text" maxLength=100 size="30" value="";" name='query' value="" alt="search">
<input alt="submit" type="submit" value="GOOGLE"><input type="radio" name="sitesearch" value="http://www.yahoo.com"/>
<label for="secondary">FIRST AREA</label><input type="radio" name="sitesearch" value="http://www.msdn.com"/>
<label for="secondary">SECONDARY AREA</label><input type="radio" name="sitesearch" value="http://www.amazon.com"/>
<label for="third">THIRD AREA</label></form>
JavaScript
<script type="text/javascript">
function changeUrl(tempUrl){
document.getElementById('newUrl').value=tempUrl;
}
</script>
HTML (also cleaned up your html a lil')
<form action="http://www.google.com/search" method="get" name="Form1"><input type="text" maxLength="100" size="30" value="" name="query" value="" />
<input alt="submit" type="submit" value="GOOGLE" /><input type="radio" name="theUrl" value="http://www.yahoo.com" onclick="changeUrl(this.value);" />
<label for="secondary">FIRST AREA</label><input type="radio" name="theUrl" value="http://www.msdn.com" onclick="changeUrl(this.value);" />
<label for="secondary">SECONDARY AREA</label><input type="radio" name="theUrl" value="http://www.amazon.com" onclick="changeUrl(this.value);" />
<label for="third">THIRD AREA</label><input type="hidden" id="newUrl" name="sitesearch" value="http://www.default_domain.com" />
</form>