• 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: Javascript

Javascript 9 years 2 months ago #30505

  • samir1
  • samir1's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
Hi,

Has anyone a ready Javascript that calculate:
If formfield1 <10 the sum is fixed = 50 else sum is formfield1 + 10


Best regards
hotis
The administrator has disabled public write access.

Javascript 9 years 2 months ago #30506

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
A quick way to achieve this would be to use something like this:
<script>
 
 
function calculate(){
	var x 			 = document.getElementById('formfield1'); // grab the first field
	var total 		 = document.getElementById('totalfield'); // grab the total
 
	if (x.value < 10) { // if it's value is smaller than 10
		total.value = 50; // the total will always be 50
	} else { // else
		total.value = parseInt(x.value) + 10; // the total value will be the formfield1 value + 10
	}
 
};
 
</script>

Next step would be to go to the Additional Attribute and trigger it somehow, as an example, you can use the formfield1's Additional Attribute and trigger it like this:
onblur = calculate();

The onblur event happens after the user deselects formfield1.

PS: This is just an example, most likely you will have to adapt it for your scenario.
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.
The following user(s) said Thank You: samir1

Javascript 9 years 1 month ago #30527

  • samir1
  • samir1's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
Hi dear cosmin.cristea,
Thank you so much for your help!!

My best wishes
hotis
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!