Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Select radio buttons automatically when input text field is clicked

Reply
Thread Tools

Select radio buttons automatically when input text field is clicked

 
 
namanhvu@gmail.com
Guest
Posts: n/a
 
      09-20-2006
Hi everyone,

I'm trying to create a form where the radio button is automatically
selected when the input text field beside it is clicked. I know I need
to use "onClick" somewhere but I don't know how.

With links I found it it would work like this:

<SCRIPT LANGUAGE="JavaScript">
function click(which) {
document.theForm.theRadio[which].checked = true;
}
</SCRIPT>

<FORM NAME="theForm">
<INPUT TYPE="RADIO" NAME="theRadio" CHECKED> <A
HREF="javascript:click(0)">Click this</A>
<BR>
<INPUT TYPE="RADIO" NAME="theRadio"> <A
HREF="javascript:click(1)">Click this</A>
</FORM>

However, with input fields, it didn't work when I tried this:

<FORM NAME="theForm">
<INPUT TYPE="RADIO" NAME="theRadio" > Button A <input type="text"
name="blah2" onClick="javascript:click(0)">
<BR>
<INPUT TYPE="RADIO" NAME="theRadio"> Button B <input type="text"
name="blah2" onClick="javascript:click(1)">
</FORM>

Can anyone help me please?

TIA.

 
Reply With Quote
 
 
 
 
Stephen Chalmers
Guest
Posts: n/a
 
      09-20-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:


> function click(which) {
> document.theForm.theRadio[which].checked = true;
> }



> <FORM NAME="theForm">
> <INPUT TYPE="RADIO" NAME="theRadio" > Button A <input type="text"
> name="blah2" onClick="javascript:click(0)">


That has the effect of calling the function named 'click' associated
with the clicked element, instead of your function with the same name.
Rename your function to something else like say fClick, then call it
thus:

onClick="fClick(0)"

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Created Radio Buttons displaying as if they were conventional buttons Dr. Leff Javascript 3 10-15-2007 09:47 PM
Created Radio Buttons displaying as if they were conventional buttons Dr. Leff Javascript 3 10-15-2007 05:18 AM
ASP.NET Reset Radio Button in a group of Radio Buttons Scott D Johnson ASP .Net 1 09-27-2006 10:38 PM
How to know which option in select field was clicked last? smash2004@gmail.com Javascript 6 10-12-2005 02:03 PM
radio button make text field equal value of form field mitch-co2 Javascript 2 02-22-2005 02:28 PM



Advertisments