• 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: Retrieving value from a radiogroup

Retrieving value from a radiogroup 14 years 2 months ago #10041

  • marioliveira
  • marioliveira's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
  • Thank you received: 1
I have a form with a radiogroup called 'Opcoes' with item such as, for example:

22|Option 1
40|Option 2
350|Option 3

the values before options representing prices

I have a hidden field called 'Total' and a text box called 'Pax' which reflects the number of people to participate in activities defined by the radiogroup options.

What I want is to multiply the 'Pax' field by the value chosen by who is submitting the form, so 22, 40 or 350.

I tried this:
document.getElementById('Total').value = parseFloat((document.getElementById('Pax').value) * (document.getElementById('Opcoes').value))

but it doesn't work. Then I saw a thread derived from the script example named something like 'performing calculations with radio groups' but I can't adpat it to my case, or at least I'm too much a beginner to be able to do it. Can anybody help me, or put me into the right track, please?

May I add that in the submissions the values for the radiogroup and the pax fields are shown:(

Thanks
Last Edit: 14 years 2 months ago by marioliveira. Reason: adding information
The administrator has disabled public write access.

Re:Retrieving value from a radiogroup 14 years 2 months ago #10068

  • andreic
  • andreic's Avatar
  • NOW ONLINE
  • RSJoomla! Official Staff
  • Posts: 733
  • Thank you received: 60
You can try using a script similar to this one in the Form Layout tab in order to calculate the Total value of the fields you are trying to multiply:
<script type="text/javascript">
function calculateField()
{
if(document.getElementsByName('form[Opcoes]')[0].checked)
document.getElementById('Total').value=parseFloat(document.getElementById('Pax').value) * parseFloat(document.getElementsByName('form[Opcoes]')[0].value);
 
if(document.getElementsByName('form[Opcoes]')[1].checked)
document.getElementById('Total').value=parseFloat(document.getElementById('Pax').value) * parseFloat(document.getElementsByName('form[Opcoes]')[1].value);
 
if(document.getElementsByName('form[Opcoes]')[2].checked)
document.getElementById('Total').value=parseFloat(document.getElementById('Pax').value) * parseFloat(document.getElementsByName('form[Opcoes]')[2].value);
 
}
</script>

The script verifies which radio button is selected from the field "Opcoes" and multiplies with the value set in the field "Pax" and sets it in the field "Total". Also you will have to add the following code line in the Additional Attributes box of the radio group field:
onclick="calculateField();"
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
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!