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

208
Views
Getting unexpected token error when try to script tag dynamically with dynamic script

Goal: Need to create multiple trigger functions dynamically for different id_numbers

I am trying to create a script tag with dynamic code but I am getting below errors

I am getting $window is not defined if I try to write below code

   $(document).ready(function() {
    var script1 = document.createElement('script');
        script1.setAttribute('type','text/javascript');
        
        //script1.text ="$(document).ready(function() {"+
        script1.text = "$window.ATL_JQ_PAGE_PROPS =  {"+
            "'id_number':{"+
                '"triggerFunction": function(showCollectorDialog) {'+
                    'jQuery("#submitBug-id_number").click(function(e) {'+
                        'e.preventDefault();'+
                        'showCollectorDialog();'+
                '   }); '+
            '}'+
        '}'+
            '}';
document.body.appendChild(script1);
});

And I have tried with different method than getting unexpected token '}'

    script1.innerHTML = "$(document).ready(function() {";
    script1.innerHTML = "$window.ATL_JQ_PAGE_PROPS =  {";
        script1.innerHTML = "'id_number' :{";
        script1.innerHTML = "'triggerFunction': function(showCollectorDialog) {";
        script1.innerHTML = "jQuery('#submitBug-id_number').click(function(e) {";
        script1.innerHTML = "e.preventDefault();";
        script1.innerHTML = "showCollectorDialog();";
        script1.innerHTML = "});";
        script1.innerHTML = "},";
        script1.innerHTML = "fieldValues: {";
        script1.innerHTML = "fullname:"+ userName+",";
        script1.innerHTML = "email: "+email+",";
        script1.innerHTML = "recordWebInfo: '1',";
        script1.innerHTML = "recordWebInfoConsent: ['1']";
        script1.innerHTML = "}";
        script1.innerHTML = "}";
        script1.innerHTML = "}";*/
        script1.innerHTML = "});";
document.body.appendChild(script1);

Please help to write a code dynamically under script tag

about 4 years ago · Juan Pablo Isaza
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!