By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,594 Members | 3,680 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,594 IT Pros & Developers. It's quick & easy.

Select radio buttons automatically when input text field is clicked

P: n/a
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.

Sep 20 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

na******@gmail.com 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)"

Sep 20 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.