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

237
Views
PHP variable added to page not populated - getting undefined in Javascript function call

I am having a bit of trouble, and i think my syntax and structure is correct but for some reason the function is failing.

products.php page

i have this function at the bottom of the page which takes the value of $child and adds it to the page, where it gets passed to the Javascript function get_child_options:

 jQuery(document).ready(function(){
      get_child_options(<?=$child;?>);
 });

The function get_child_options is added by my footer.php page

footer.php

function get_child_options(selected){
   if(typeof selected === 'undefined'){
       var selected = '';
   }
   var parentID = jQuery('#parent').val();
   $.ajax({
     url: '/admin/parsers/child_categories.php',
     type: 'POST',
     data: {parentID: parentID, selected: selected},
     success: function (data){
         jQuery('#child').html(data);
     },
     error: function(){alert("Something went wrong with the child options.")},
     });
  }
  jQuery('select[name="parent"]').change(get_child_options);

The error when i load products.php is get_child_options is not declared I have had a look online and via this forumn and i think the makeup of my function within my products.php page is correct, i just don't understand why its not recognising the function is declared within my footer.php and processing the function.

To add, i have tried this within the function on my products.php page but i got rid of the undefined error but the function didnt pass any data to my get_child_options function.

jQuery(document).ready(function(){
    function getchild(child){
        var child = <?=$child;?>
        get_child_options(child);
    }
});

If anyone can help, that would be great and i can't think of what i am doing wrong. TIA

I have reviewed How can I call PHP functions by JavaScript? and feel my situation is different to theres.

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

0

I found the issue and it was that my parsers file couldn't see my authentication file to get the function. Once i had add the correct path to the file it all worked.

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!