• 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: Simple Show/Hide Field Javascript Question

Simple Show/Hide Field Javascript Question 13 years 8 months ago #11167

  • didomi
  • didomi's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
This should be quite simple but I've been scratching my head for some time now!

I've followed this tutorial which gets me to about 90% of where I need to be which is great... http://www.rsjoomla.com/customer-support/documentations/34-custom-scripting/93-show-or-hide-fields.html.

So now I have a form where by clicking on certain radio buttons hides certain fields. But how do I set it up so the default state is to have those fields hidden and clicking on certain radio buttons reveals them?

Here's a snippet of the Javascript I'm using in the form layout box...
<script type="text/javascript">
 
function displayStyleOptions() {
 
if(document.getElementsByName('form[style]')[0].checked) {
document.getElementById('hideI').style.display="none"
document.getElementById('hideAtoH').style.display="";
}
 
if(document.getElementsByName('form[style]')[1].checked) {
document.getElementById('hideI').style.display="none"
document.getElementById('hideAtoH').style.display="";
}
 
}

Hope someone can help,
Chris
The administrator has disabled public write access.

Re:Simple Show/Hide Field Javascript Question 13 years 8 months ago #11183

  • bogdanc
  • bogdanc's Avatar
  • OFFLINE
  • Moderator
  • Posts: 669
  • Thank you received: 11
Hello,

You can try setting the script to something like this:
<script type="text/javascript">
 
function displayStyleOptions() {
 
if(document.getElementsByName('form[style]')[0].checked) {
document.getElementById('hideI').style.display="none"
document.getElementById('hideAtoH').style.display="";
}
 
if(document.getElementsByName('form[style]')[1].checked) {
document.getElementById('hideI').style.display="none"
document.getElementById('hideAtoH').style.display="";
}
 
}
displayStyleOptions();
</script>

Let me know if this works for you.
The administrator has disabled public write access.

Re:Simple Show/Hide Field Javascript Question 13 years 8 months ago #11186

  • didomi
  • didomi's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
Solved...I needed to initiate the JavaScript when the form loaded, not simply when the first radio was clicked...
<script type="text/javascript">
displayStyleOptions();
</script>

...simples
The administrator has disabled public write access.

Re:Simple Show/Hide Field Javascript Question 13 years 8 months ago #11188

  • lucrece
  • lucrece's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
I did this and got a strange:
id="hide"> id="hide">
now at the top of my form just under the title.

I did this as per the instructions:
The element I am trying to use to determine the conditional is called "Client Pages." In additional attributes I put this code:
onclick="displayField();"

Then in the Form Layout, I inserted this code at the end of the table:
<script type="text/javascript">
function displayField()
{
if(document.getElementsByName('form[Client Pages]')[0].checked)
document.getElementById('hide').style.display="none";

if(document.getElementsByName('form[Client Pages]')[1].checked)
document.getElementById('hide').style.display="";
}
</script>

Then I inserted "id="hide"" into the two elements that I want to be conditional based on the Client Pages radio group.

I don't really understand how this is supposed to be working because the tutorial isn't very clear. Can someone explain?
The administrator has disabled public write access.

Re:Simple Show/Hide Field Javascript Question 13 years 2 months ago #12692

  • spartan
  • spartan's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
and this code is placed into the default values field of the form field we want to show if the radio button is clicked or does this go into the radio button default values field?
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!