Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda