Mat5hias Mat5hias - 1 year ago 105
PHP Question

Execute jQuery script if value is 1 inside a php echo in Joomla

I like to execute a jQuery Script if "Yes" is selected in the radio button. I am getting confused of how to implement the addScriptDeclaration from Joomla inside an echo, also I'm not sure if the call

if (count($displayonload) == '1'){
is the right way to get the value from the checkbox.

Explaining the xml code: The radio button in the backend of Joomla with value 0 if no and value 1 if yes is selected.

<field name="displayonload"
type="radio" default="0"
label="Display Modal on load"
class="btn-group btn-group-yesno">
<option value="1">JYES</option>

The value 1 or 2 is stored like this:

$displayonload = $params->get('$displayonload');

The php code to echo the js script (jQuery):

if (count($displayonload) == '1'){
echo '
$document = JFactory::getDocument();


Sorry if my code is a mess but I'm just starting with Joomla and PHP development.

Answer Source

I found the solution, may this will help someone.

if ($params->get('displayonload', '0') == '1') {
      $document = JFactory::getDocument();
    $js = 'jQuery(window).load(function(){

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download