• 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: Show/hide fields using a checkbox

Show/hide fields using a checkbox 13 years 1 week ago #13560

  • fredmi
  • fredmi's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
Hello,

I'm trying to show / hide multiple fields using a checkbox (and not a radio button).

But unfortunately... it does not completely works.
Fields with 'hide1' & 'hide2' IDs are not visible in the form (yepeee this part is OK > window.addEvent works).
But when I click on the checkbox to display fields, nothing happens.

Any idea? Thanks for help ! Here is my code...


<script type="text/javascript">
function displayField()
{
if(document.getElementsByName('form[Checkk]').checked)
{
document.getElementById('hide1').style.display="";
document.getElementById('hide2').style.display="";
}
else
{
document.getElementById('hide1').style.display="none";
document.getElementById('hide2').style.display="none";
}
}
</script>

<script type="text/javascript">
window.addEvent('domready', function() {
displayField();
});
</script>
The administrator has disabled public write access.

Re:Show/hide fields using a checkbox 13 years 1 week ago #13575

Hello,
I'm not a programmer but I do look at the code posted in the forum to help me learn. I posted to the mods about what the code should look like without the emoticons in it. I don't use them so I don't know off-hand what characters make up each one. And I figured that the character sequence was important.
What I got back may be of help to you:
___________________________
The respective code lines from the forum post should be like this:

document.getElementById('hide1').style.display="";
document.getElementById('hide2').style.display="";

document.getElementById('hide1').style.display="none";
document.getElementById('hide2').style.display="none";

However, in order to show/hide fields with checkboxes you can use the same script used in our example from the documentation with the radio buttons:

www.rsjoomla.com/customer-support/docume...-or-hide-fields.html

All you will have to change in the example so that it will work are 2 lines. Let's say that you have check-box field named "check" . So the 1st line you will have to change is this one:

if(document.getElementsByName('form[Radio]')[0].checked)

it will be changed to:

if(document.getElementById('check0').checked)

And the 2nd one is this:

if(document.getElementsByName('form[Radio]')[1].checked)

it will be changed to:

if(document.getElementById('check1').checked)

So instead of "getting" the element from the check-box by name they will taken by id. And the id of the elements from the check-box is formed from the name of the field plus the index from the item list (beginning from 0 not 1).
In conclusion if you have a check-box field named "field" and 3 items (item1, item2 and item 3) , the id for the items are these:

item1 has the id: field0
item2 has the id: field1
item3 has the id: field2

Regards!
________________________
Since you do read/write code, I'm sure you can figure out what they are suggesting. If possible, could you post your site address when you get this working so we can see the form in action? I'm sure all forum members would appreciate it.
Kathy Ahrendt
Web Manager, www.nemgtr.org
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!