• 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: Problems with show/hide fields

Problems with show/hide fields 13 years 3 months ago #16021

  • eva111
  • eva111's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
I have a form where two different radio groups hide/show different fields depending on what is selected.
The hide/show part works but the following things do not.

1) a field should be required when it is visible and not when it is hidden.
2) when loading the page the fields should be hidden and only appear when the radio button making them visible is selected.


The radio group has a 'onclick="NameOfFunction();" in the 'Attributes'.
In the 'Form Layout' tab I put id="" in the tr tags.

My hide/show code in the 'CSS and Javascript' tab is as follows:
<script type="text/javascript">
 
function membershipNew() {
 
if(document.getElementsByName('form[membership]')[0].checked) {
document.getElementById('hidea').style.display="none"
document.getElementById('hideb').style.display=""
document.getElementById('hidec').style.display="";
}
 
if(document.getElementsByName('form[membership]')[1].checked) {
document.getElementById('hidea').style.display=""
document.getElementById('hideb').style.display="none"
document.getElementById('hidec').style.display="none";
}
 
}
 
 
function paymentSel() {
 
if(document.getElementsByName('form[payment]')[0].checked) {
document.getElementById('hide1').style.display="none"
document.getElementById('hide2').style.display="none"
document.getElementById('hide3').style.display="none"
document.getElementById('hide4').style.display="none";
}
 
if(document.getElementsByName('form[payment]')[1].checked) {
document.getElementById('hide1').style.display=""
document.getElementById('hide2').style.display=""
document.getElementById('hide3').style.display=""
document.getElementById('hide4').style.display="";
}
 
}
</script>

I tried tackling problem 1) with the following code (as seen in a tutorial) placed after the last } and before </script>
function validateField()
{
if(document.getElementById('hide1').style.display=="" && document.getElementById('bank').value=="")
{
document.getElementById('component30').className = 'formError';
return false;
}
else
{
document.getElementById('component30').className = 'formNoError';
return true;
}
}

bank is the name of one of the fields that should be require input when visible and no input when hidden.
component30 is the component number of bank as seen on the source code.
The code has no effect as far as I can see, if I chose 'required:yes' in the backend 'bank' is always required, when I chose no it never is, no idea what I'm doing wrong.

For 2) I tried this code (also seen in the tutorial)with no visible effect.
window.addEvent('domready', function() {
paymentSel();
});

I guess I'm not well versed enough in javascript to adapt the tutorial code to my own needs, beats me what I'm doing wrong. Any help would be appreciated.
The administrator has disabled public write access.

Re: Problems with show/hide fields 13 years 2 months ago #16203

  • obuoho
  • obuoho's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
I'm looking for a solution as well. I tried the tutorial and it did not work for me after spending many hours trying to make it work.
The administrator has disabled public write access.

Re: Problems with show/hide fields 13 years 2 months ago #16223

  • alexp
  • alexp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 2253
  • Thank you received: 180
Hello,

I would recommend implementing the validation part with PHP, via the $invalid method, described here:

http://www.rsjoomla.com/support/documentation/view-article/602-php-scripts.html
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
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!