Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can set jinja variable in javascript function?

function show_modal(val1, val2){
    {% set msg1 = val1 %}
    {% set msg2 = val2 %}
    document.getElementById('id01').style.display='block'
}

I have calling show_modal() function in some where in the template.

Needs each time assigning situational values to msg1 and msg2

Not working. Each not working below:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

function show_modal(){
    {% set msg1 = "Delete Column" %}
    {% set msg2 = "Are you sure you want to delete this column?" %}
    document.getElementById('id01').style.display='block'
}

May I show different prompts with this part of code? (Which is invisible by default)

<div id="id01" class="modal">
        <h1>{{ msg1 }}</h1>
        <p>{{ msg2 }}</p>
</div>

>Solution :

You have to use pure js for this, try something like this:

function show_modal(){
   let msg1 = "Delete Column";
   let msg2 = "Are you sure you want to delete this column?";
   document.getElementById("id01").innerHTML=`
     <h1>${msg1}</h1>
     <p>${msg2}</p>`;
   document.getElementById('id01').style.display='block'
 }

<div id="id01" class="modal">
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading