• 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: Field shown based on another field result number

Field shown based on another field result number 1 year 4 months ago #43171

I have this form:

Field 1: input number
Field 2: input number
Field 3: Result of Field 1/Field 2

Filed 4: should show if Field 3 is above 0.5 and less than 0.75.

I have Field 1 to 3 figured. Just can´t get the JavaScript right to show Field 4.

Could you help me?
The administrator has disabled public write access.

Field shown based on another field result number 1 year 4 months ago #43173

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 246
  • Thank you received: 64
Without testing I can't gurantee it will work seamlessly but try this function
function updateFieldVisibility() {
            // Get the values of Field 1 and Field 2
            var field1Value = parseFloat(document.getElementById('field1').value);
            var field2Value = parseFloat(document.getElementById('field2').value);
 
            // Calculate the result of Field 1 / Field 2
            var field3Result = field1Value / field2Value;
 
            // Get the reference to Field 4
            var field4 = document.getElementById('field4');
 
            // Check if Field 3 is above 0.5 and less than 0.75
            if (field3Result > 0.5 && field3Result < 0.75) {
                // Show Field 4
                field4.style.display = 'block';
            } else {
                // Hide Field 4
                field4.style.display = 'none';
            }
        }

call it in fields 1&2 every time the values are changed with the following:
oninput="updateFieldVisibility()"

finally in field 4 add style="display:none;" so it's not shown by default.
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.

Field shown based on another field result number 1 year 4 months ago #43174

thanks. is not working though.
try also to reduce it to:

<script>
function updateFieldVisibility() {
// Get the reference to Field 4
var field4 = document.getElementById('field4');

// Check if Field 3 is above 0.5 and less than 0.75
if (field3Result > 0.5 && field3Result < 0.75) {
// Show Field 4
field4.style.display = 'block';
} else {
// Hide Field 4
field4.style.display = 'none';
}
}
</script>

since the field 1 and 2 division can be simple done with an rs form calculation.





Field 4 is not displaying at all.
The administrator has disabled public write access.

Field shown based on another field result number 1 year 4 months ago #43175

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 246
  • Thank you received: 64
Isn't it the case that if you use a calculation it's only carried out on form submit in which case the field 3 contains zero or nothing? I think you need to carry out the / in real time so that field three contains a value to allow field 4 to show or not
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
Last Edit: 1 year 4 months ago by iceferret.
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!