• 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: Calculate Problem

Calculate Problem 14 years 1 month ago #10121

Hi, i create form with 1 textbox field named "Field1" and i create 3 radio buttons (with radio group - but i create just one radio button), named radio1, radio2, radio3.I create hidden field named "result" and button "Submit"

I want then i press "Submit" button to get value of "Field1" and if "radio1" is checked to calculate : Result = Field1* 2,5;

If f "radio2" is checked to calculate : Result = Field1* 3,5;
If "radio3" is checked to calculate : Result = Field1* 4,5;
If "radio1" and "radio2" is checked : Result = Field1*2 + Field*3,5;
If "radio1" and "radio3" is checked : Result = Field1*2 + Field*4,5;
If "radio2" and "radio3" is checked : Result = Field1*3,5 + Field*4,5;
If "radio1" and "radio2" and radio3 is checked : Result = Field1*2 + Field*3,5 + Filed1*4,5;

:(
I try to create java script for example:

<script type="text/javascript">
function calculate()

{

if(document.getElementsByName('form[radio1')[0].checked)
document.getElementById('result').value=parseFloat(document.getElementById('Field1').value) * 2;

if(document.getElementsByName('form[radio2]')[1].checked)
document.getElementById('result').value=parseFloat(document.getElementById('Field1).value) * 3,5;

if(document.getElementsByName('form[radio3]')[1].checked)
document.getElementById('result').value=parseFloat(document.getElementById('Field1).value) * 4,5;

if(document.getElementsByName('form[radio2]')[1].checked) and (document.getElementsByName('form[radio3]')[1].checked)
document.getElementById('result').value=parseFloat(document.getElementById('Field1).value) * 2 + parseFloat(document.getElementById('Field1').value) * 3,5;

...


alert(result.value);

return false;
</script>

And put this script to Form Layout with Auto Generate Layout OFF, BUT NOT WORK!

Can help me, please :)
Last Edit: 14 years 1 month ago by vladimirnt.
The administrator has disabled public write access.

Re:Calculate Problem 14 years 1 month ago #10129

  • bogdanc
  • bogdanc's Avatar
  • OFFLINE
  • Moderator
  • Posts: 669
  • Thank you received: 11
Hello,

Please try using a script similar to this one in order to achieve what you wish:
<script type="text/javascript">
function calculate()
 
{
 
if(document.getElementsByName('form[radio1]')[0].checked)
document.getElementById('result').value=parseFloat(document.getElementById('Field1').value) * 2;
 
if(document.getElementsByName('form[radio2]')[0].checked)
document.getElementById('result').value=parseFloat(document.getElementById('Field1').value) * 3,5;
 
if(document.getElementsByName('form[radio3]')[0].checked)
document.getElementById('result').value=parseFloat(document.getElementById('Field1').value) * 4,5;
 
if(document.getElementsByName('form[radio2]')[0].checked) && (document.getElementsByName('form[radio3]')[0].checked)
document.getElementById('result').value=parseFloat(document.getElementById('Field1').value) * 2 + parseFloat(document.getElementById('Field1').value) * 3,5; 
 
alert(document.getElementById('result').value);
}
</script>

Also please do not forget to place the trigger of the function in the Additional Attributes section of the Submit button:
onclick="calculate();"
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!