Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Select radio buttons automatically when input text field is clicked (http://www.velocityreviews.com/forums/t927090-select-radio-buttons-automatically-when-input-text-field-is-clicked.html)

namanhvu@gmail.com 09-20-2006 03:23 PM

Select radio buttons automatically when input text field is clicked
 
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.


Stephen Chalmers 09-20-2006 08:50 PM

Re: Select radio buttons automatically when input text field is clicked
 

namanhvu@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)"



All times are GMT. The time now is 05:54 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.