force one radio button to take a value from another one

E

ed 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
 
M

Michael Winter

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

The language attribute isn't necessary.
function forceCompPay() {

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

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.
 
E

ed a

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

Thanks a million!

Ed

Michael Winter said:
ed a wrote on 21 Nov 2003:
<script language="JavaScript" TYPE="text/javascript">

The language attribute isn't necessary.
function forceCompPay() {

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top