Connecting Tech Pros Worldwide Help | Site Map

force one radio button to take a value from another one

  #1  
Old July 20th, 2005, 01:02 PM
ed a
Guest
 
Posts: n/a
Hello,

I am a complete JS newbie. I am trying to make one radio button assume
a certain value when another one in a different group is clicked. This
is a conference registration form for which most applicants will pay,
but some do not. It is passing form data to a ColdFusion backend, and
I simply wish to have
the non-paying applicants have the no-pay "payment type" automatically
selected
when they select the no-pay registration type. I have tried the
following with no success (in IE 6.0; I want to test it here first)

<script language="JavaScript" TYPE="text/javascript">

function forceCompPay() {

if (document.forms[1].groupType == "speaker") {
document.forms[1].groupPayment[comp].checked = true

}
}
</script>
</head>

the "master" button is:
<cfinput type="radio" name="type" value="speaker"
onClick="forceCompPay()">Speaker

the "slave" button is :

<cfinput type="radio" name="payment" value="comp">&nbsp;Comp

everyone else would need to manually select the other payment types.
Any input would be vastly appreciated.

Ed
  #2  
Old July 20th, 2005, 01:02 PM
Michael Winter
Guest
 
Posts: n/a

re: force one radio button to take a value from another one


ed a wrote on 21 Nov 2003:
[color=blue]
> <script language="JavaScript" TYPE="text/javascript">[/color]

The language attribute isn't necessary.
[color=blue]
> function forceCompPay() {
>
> if (document.forms[1].groupType == "speaker") {
> document.forms[1].groupPayment[comp].checked = true
> }
> }[/color]

First, a few assumptions:

The name of the form is "register".*
The name of the delegate type radio buttons is "type".
The name of the payment type radio buttons is "payment".
The "speaker" delegate type is the first (index 0) button in "type".
The "no payment" payment type is the third (index 2) button in
"payment".

// If "speaker" is selected...
if (document.forms['register'].elements['type'][0].checked)
{
// ...set the payment type to "no payment"
document.forms['register'].elements['payment'][2].checked = true;
}

All you need to do is change the form name, radio button group names,
and the button indicies**.

Hope that helps.

Mike


* Using the form name is better than an index (easier maintenance).
** Despite the note above, you have no choice but to use the index.

--
Michael Winter
M.Winter@blueyonder.co.uk.invalid (remove ".invalid" to reply)
  #3  
Old July 20th, 2005, 01:02 PM
ed a
Guest
 
Posts: n/a

re: force one radio button to take a value from another one


It certainly did. Now I can put back all the hair I pulled out ;-)

Thanks a million!

Ed

Michael Winter <M.Winter@blueyonder.co.uk.invalid> wrote in message news:<Xns943AE07C09779MWinterBlueyonder@193.38.113 .46>...[color=blue]
> ed a wrote on 21 Nov 2003:
>[color=green]
> > <script language="JavaScript" TYPE="text/javascript">[/color]
>
> The language attribute isn't necessary.
>[color=green]
> > function forceCompPay() {
> >
> > if (document.forms[1].groupType == "speaker") {
> > document.forms[1].groupPayment[comp].checked = true
> > }
> > }[/color]
>
> First, a few assumptions:
>
> The name of the form is "register".*
> The name of the delegate type radio buttons is "type".
> The name of the payment type radio buttons is "payment".
> The "speaker" delegate type is the first (index 0) button in "type".
> The "no payment" payment type is the third (index 2) button in
> "payment".
>
> // If "speaker" is selected...
> if (document.forms['register'].elements['type'][0].checked)
> {
> // ...set the payment type to "no payment"
> document.forms['register'].elements['payment'][2].checked = true;
> }
>
> All you need to do is change the form name, radio button group names,
> and the button indicies**.
>
> Hope that helps.
>
> Mike
>
>
> * Using the form name is better than an index (easier maintenance).
> ** Despite the note above, you have no choice but to use the index.[/color]
Closed Thread