Skip to main content
Topic: set variable in custom js (Read 1204 times) previous topic - next topic

set variable in custom js

Code: [Select]
$(document).ready(function() {
   
var agency1 = "get_active_user('agency')";
alert('agency1');
if(agency1=="redkey"){
    alert('agency1');
}
else{
   
}
});

i try to set a variable with a helper code in custom JS, but get_active_user() do not work.

i want to set the variable and if agency = A, then show an iframe for agency A

how to set the variable on page load and pass the variable to the custom view?

thanks in advance!

Re: set variable in custom js

Reply #1
@andrewmak‍ you cannot use a PHP code inside a js code that will be generated in a .js file. If you want to do that, edit your page as custom and add your code at the bottom of the page.

Code: [Select]
$(document).ready(function() {
var agency1 = "<?php echo get_active_user('agency'); ?>";
alert('agency1');
if(agency1=="redkey"){
    alert('agency1');
}
else{
  
}
});

Re: set variable in custom js

Reply #2
@willvin
i only have very basic knowledge of php, now i know the code wont work in javascript. thanks

the page i try to set variable and run if/else command is a role base dashboard, it do not have a page for custom editing, how to do it in this case?

here is what i am trying to do, i have dashboard for user role = agency... when the agency user login he will see an embaded iframe dashboard by google datastudio.

so i want to get the user agency name get_active_user('agency');
if agency = A, then i set the iframe url belong to A
if agency = B, then i sent iframe url for B....

this way the user will only see his own data.

the page event function only have even for before and after ADD, but dont have a page ON LOAD option.

please advice, thanks a lot!