• 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: Output a specific text in text field -

Output a specific text in text field - 7 months 3 weeks ago #42969

  • khnoiel
  • khnoiel's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
I have a textbox (textfieldA) with input the age of a person.

e.g., 25

in another textbox (textfieldB) should the output

e.g., age 18 in textfieldA --> age 0-20 (textfieldB)
e.g., age 25 .......--> age 21-40.......
e.g. age 43 ........--> age 41-60.......
.....

Has anyone a solution for me?
The administrator has disabled public write access.

Output a specific text in text field - 7 months 3 weeks ago #42971

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 216
  • Thank you received: 57
Add this function in your forms 'properties/javascript area
 function calculateAgeRange() {
  // Get the input age from textfieldA
  var ageInput = document.getElementById("textfieldA").value;
 
  // Convert the input to a number
  var age = parseInt(ageInput);
 
  // Define age ranges
  var ageRanges = [
    { min: 0, max: 20, label: "Age 0-20" },
    { min: 21, max: 40, label: "Age 21-40" },
    { min: 41, max: 60, label: "Age 41-60" },
    // Add more ranges as needed
  ];
 
  // Find the appropriate age range
  var ageRange = "Unknown"; // Default value if age is not within any defined range
 
  for (var i = 0; i < ageRanges.length; i++) {
    if (age >= ageRanges[i].min && age <= ageRanges[i].max) {
      ageRange = ageRanges[i].label;
      break; // Exit the loop once we find the range
    }
  }
 
  // Update textfieldB with the age range
  document.getElementById("textfieldB").value = ageRange;
}
  }

call the code in the fieldA's 'attributes' using
onChange="calculateAgeRange();"

You'll obviously need to modify the field names to represent whatever you name them if not fieldA or fieldB
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
Last Edit: 7 months 2 weeks ago by iceferret. Reason: duplicated line in code
The administrator has disabled public write access.
The following user(s) said Thank You: khnoiel

Output a specific text in text field - 7 months 2 weeks ago #42974

  • khnoiel
  • khnoiel's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
@iceferret

Thank you - works perfect
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!