Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

radio button input

Status
Not open for further replies.

zngo

Technical User
May 30, 2003
21
0
0
US
I just started learning javascript and I wanted to make an interface to the google search engine. I went on to implement the feature that filters languages and I found that I need to use a radio button set to do this.

I have looked around for ways to get values from radiobutton sets. I seem to always come across this one method..:

<input type=&quot;radio&quot; onClick=&quot;someFunction('value')&quot;>
// then the function would have the 'value' parameter..

I want to be able to (within js) use the value of the box that is checked. My method (that failed?) can be found here:

// the javscript part::
function searchgoogle(){
var url=window.document.googleform.url.value.split(&quot; &quot;);
var output=&quot;&quot;;
var lang=&quot;&quot;;
var options=window.document.googleform.language.length;
for (i=0; i<=options; i++){
if (window.document.googleform.language){
lang = window.document.googleform.language.value;
}
}
for (i=0; i<=url.length; i++){
output+=&quot;+&quot;+url;
}
output=output.substr(1,output.length-11);
window.open(&quot;}

<!-- the html:: -->
<form name=&quot;googleform&quot;>
<input type=&quot;text&quot; name=&quot;url&quot;>
<a href=&quot;javascript:searchgoogle()&quot;>Search</a>&nbsp;|&nbsp;<a href=&quot;javascript:reseturl()&quot;>Reset</a>
<br />
<input type=&quot;radio&quot; name=&quot;language&quot; value=&quot;&lr=lang_en&quot;>English
<input type=&quot;radio&quot; name=&quot;language&quot; value=&quot;&lr=lang_de&quot;>German
<br /><br />/* Looking for features to add... */
</form>

If you want to see the site live, its here:
Thanks for your time..
-Zach Ngo
 
lol, that didn't do much. I think I know what i need to find out.

Is there any way you can check on the condition of a radio button? like give it a test? Is there something like:

if (window.document.form.radiobutton[3].checked == true){
// blah blah blah
}

(?)

-Zach Ngo
 
the site i showed you uses the function as a generic operator for all the buttons, but to check for one button, you can use...
if (document.formName.radioName.checked==true){
blah blah}

HOWEVER, that is for only one specific button, not multiple ones

Later,
Greelmo
 
and yes, the radioName[radio-index] works for all of them

Later,
Greelmo
 
Well, I played with this (FOR A FEW HOURS! :p). loser.. yeah, well I decided to make a hidden element in the googleform form and make the onClick of the language radio button change the hidden element's value. when the actual function that opens the google search does its thing, it will append the value of the hidden element in the googleform form, making my script work fine, i think.

Thanks Greelmo for taking the time to look at my problem and for giving me the drive to solve this problem.

-Zach Ngo
 
my pleasure, and that is a very efficient way to solve the problem! good job.

Later,
Greelmo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top