Forums

Hide/Show an element

philpil 18 Feb, 2015
Hi,
I'd like to hide/show an element as a variable (if ($tt==1){ } ) but I don't know how to do. Could you please help me.
Thank you
GreyHead 19 Feb, 2015
Hi philphil,

The quick and dirty approach is with CSS. Add this to a Custom Code action in the form OnLoad event
<?php
$show_me = 'block';
if ( $form->data['some_name'] != 1 ) {
  $show_me = 'none';
}
$jdoc = JFactory::getDocument();
$style = ".show_hide { display: '{$show_me}'; } ";
$jDoc->addStyledeclaration($style);
?>
The add the class show_hide to to the element

For blocks of elements you can do something similar with containers.

Bob
philpil 19 Feb, 2015
Hi Bob,
Thank you very much for your help but the program is not working ! I have changed "$jdoc->addStyleDeclaration" but it's not enough and i'm not sure of the true words.
(excuse my bad english)
Thanks
GreyHead 20 Feb, 2015
Hi philpil,

Please post a link to the form so I can take a quick look.

Bob
philpil 23 Feb, 2015
Hi Bob,
I have made a small form with a Custom Code action in the form OnLoad event with this :
<?php
$form->data['some_name']= 2;
$show_me = 'block';
if ( $form->data['some_name'] != 1 ) { $show_me = 'none';}
$jdoc = JFactory::getDocument();
$style = ".show_hide { display: '{$show_me}'; } ";
$jdoc->addStyleDeclaration($style);
?>
and a container with

Container Class = show_hide
Start Code = <div id='block'>
End Code = </div>
The container is visible (with some_name= 1 or 2) but i'm a beginner and certainly something is missing !
Thank you very much if you have time to help me.
philpil 12 Mar, 2015
Hi,
there is an easy solution. To do this, two containers must be use with the selection "Custom". Write in the first:
<?php
$display = 'none';
if ( $form->data['some_variable'] == 'no' ) {$display = 'block';}
echo "<fieldset style='display:{$display};' >
  <legend>Some Title</legend> ";
?>

and in the second :
</fieldset>

I have found this solution in the forum.
Best regards
This topic is locked and no more replies can be posted.