Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
Get value from javascript dict in odoo template's script tag

I need to get the value of elt.innerHTML and pass it to fromPage[j].textContent.

Function borrowed from GitHub.

Currently vars['hiddenNumber'] is returning undefined.

elt.style.visibility = "hidden"; works as intended tho.

I believe this might be related with variable scopes, but can't seem to find a way to create a global variable. Tried to update window.value, but got an error that window is not defined.

Using odoo 13, wkhtmltopdf 0.12.5.

<script>
    function subst() {
        var vars = {};
        var x = document.location.search.substring(1).split('&amp;');
        for (var i in x) {
            var z = x[i].split('=', 2);
            vars[z[0]] = unescape(z[1]);
        }
        var index = vars['webpage'].split('.', 4)[3]

         var operations = {
                    // other operations
             'hidden_page_number': function (elt) {
                 elt.style.visibility = "hidden";
                 vars['hiddenNumber'] = elt.innerHTML;  // This value
             },
         };

         for (var klass in operations) {
             var y = document.getElementsByClassName(klass);
             for (var j=0; j&lt;y.length; ++j)
             operations[klass](y[j]);
         }

         var fromPage = document.getElementsByClassName('page');
         for(var j = 0; j&lt;fromPage.length; j++)
         fromPage[j].textContent = vars['hiddenNumber'];  // Required here

         var toPage = document.getElementsByClassName('topage');
         for(var j = 0; j&lt;toPage.length; j++)
         toPage[j].textContent = vars.sitepages;
 }
</script>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

just a suggestion: you define vars outside the closure and then define closure where try to update vars but I suppose that inside the closure it creates new scope for vars and that's why vars is not updated outside

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!