Forum Moderators: open

Message Too Old, No Replies

HELP! Easy question for Javascripters!

         

Celeste

11:01 pm on Sep 6, 2007 (gmt 0)

10+ Year Member



Hello,

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>

Trace

7:57 pm on Sep 10, 2007 (gmt 0)

10+ Year Member



You're making it too complex than it needs to be. You don't need to use the hidden field, just use radio buttons. Google does the rest.

<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>

Trace

8:04 pm on Sep 10, 2007 (gmt 0)

10+ Year Member



If you really want to use the hidden field, here's how;

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>