• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: capturing radio button text values

capturing radio button text values 11 years 5 months ago #25807

  • lcbarker
  • lcbarker's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
I'm working with the Calculations Example form. The JavaScript is:
function calculateRadio()
{
var op1=document.getElementsByName('form[radio1]');
var op2=document.getElementsByName('form[radio2]');
var result=document.getElementById('Total2');
 
result.value=0;
 
result.value=parseInt(result.value);
 
for(i=0;i<op1.length;i++)
if(op1[i].checked) result.value=parseInt(result.value)+parseInt(op1[i].value);
 
for(i=0;i<op2.length;i++)
if(op2[i].checked) result.value=parseInt(result.value)+parseInt(op2[i].value);
}

This takes the value of the radio buttons, which are numbers, and does numerical calculations.

What I would like to do is just return values (ie PEDA) as straight text. Then I can use the text in an if .. then code.

But I can't figure out how to get the text values and save them to a variable as text.

Your help is appreciated.

Les
The administrator has disabled public write access.

capturing radio button text values 11 years 5 months ago #25814

  • lcbarker
  • lcbarker's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
I got it to work. For the benefit of others here are the details.

This is for a registration form for a conference. I needed to capture the text value of the radio button to indicate the registration category. Then I use this code to assign the fee value to the registration through use of an if ... then .. routine. Then the fee is assigned to a field which is used to send a thank you message and for sending to paypal.

Here is the resultant code:
<script type="text/javascript">
function calculateRadio()
{
var radios = document.getElementsByName('form[rgcategory]');
var result=document.getElementById('rgfee');
 
            for (var i=0; i < radios.length; i++) {
                if (radios[i].checked) {
		       vcrgfee=radios[i].value;
if (vcrgfee== "IED1")
   {
   vRgFee=30;
   }
 else if (vcrgfee== "IED2")
   {
   vRgFee=30;
   }
 else if (vcrgfee== "IEDA")
   {
   vRgFee=50;
   }
 else if (vcrgfee== "PED1")
   {
   vRgFee=60;
   }
 else if (vcrgfee== "PED2")
   {
   vRgFee=60;
   }
 else if (vcrgfee== "PEDA")
   {
   vRgFee=100;
   }
 else if (vcrgfee== "SED1")
   {
   vRgFee=20;
   }
 else if (vcrgfee== "SED2")
   {
   vRgFee=20;
   }
 else if (vcrgfee== "SEDA")
   {
   vRgFee=30;
   }
 else if (vcrgfee== "ROD1")
   {
   vRgFee=0;
   }
 else if (vcrgfee== "ROD2")
   {
   vRgFee=0;
   }
 else if (vcrgfee== "RODA")
   {
   vRgFee=0;
   }
 else if (vcrgfee== "KOD1")
   {
   vRgFee=0;
   }
 else if (vcrgfee== "KOD2")
   {
   vRgFee=0;
   }
 else if (vcrgfee== "KODA")
   {
   vRgFee=0;
   }
 else if (vcrgfee== "TOD1")
   {
   vRgFee=0;
   }
 else if (vcrgfee== "TOD2")
   {
   vRgFee=0;
   }
 else if (vcrgfee== "TODA")
   {
   vRgFee=0;
   }
 else
   {
   vRgFee="?";
   }
result.value=vRgFee;
                }
            }
 
}
</script>

The code is called by onClick="calculateRadio();" placed in the radio button Attributes field.
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!