• 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: Hide/show field dynamicaly with radio button

Hide/show field dynamicaly with radio button 6 years 10 months ago #36844

Hi,

I want to display or hide a field dynamicaly, when I clic on a the third radio button of a group of three radio button.

I have added javascript as described into documentation:

<script type="text/javascript">
function displayField()
{
if(document.getElementsByName('form[choix]')[0].checked)
document.getElementById('description_activite').style.display="none";

if(document.getElementsByName('form[choix]')[1].checked)
document.getElementById('description_activite').style.display="none";

if(document.getElementsByName('form[choix]')[2].checked)
document.getElementById('description').style.display="";

alert("Coucou");
}
window.onload = function() {
displayField();
};
</script>

When the form is loaded, the field is correctly hide or show depending of default choice, but when I clic on radio buttons nothing is happening, the function is not called, however I have added onclick="displayField();" into attributs box of radio button group.

I have also tried with conditionnal option of RSFrom!Pro without success.

I you can help me.
Thank you in advance.
The administrator has disabled public write access.

Hide/show field dynamicaly with radio button 6 years 5 months ago #37442

  • master5
  • master5's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Hi,

I had the same problem and solved it.

So, If you didn't solve this earlier.

I had two radio button groups I wanted to hide on page load and then select one.
This is how I did it.
1. The radio buttons do not have name with a number – though they have a unique id – in your case "choix1", "choix2" and so on.
Therefore use "getElementById('choix1')"…
2. The form element and the label is contained in a "div" – without an id
Set an id manually to this div in the Form Layout.

Than it should work properly.

This is how my code looks like.
<script type="text/javascript">
function displayGender() {
  if(document.getElementById('gender0').checked || document.getElementById('gender1').checked){
    if(document.getElementById('gender0').checked){
      document.getElementById('men').style.display="";
      document.getElementById('ladies').style.display="none";
    }
    if(document.getElementById('gender1').checked){
      document.getElementById('men').style.display="none";
      document.getElementById('ladies').style.display="";
    }
  }else{
      document.getElementById('men').style.display="none";
      document.getElementById('ladies').style.display="none";
  }
}
window.onload = function(){
displayGender();
};
</script>
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!