I'm trying to pass 2 variables through a php function's parameters to be use by the javascript's trigger function but the javascript's trigger function is not accepting the 2 variables. Not sure what I did wrong. Please take a look:
trigger.php
<?php
function trigger($type,$name) {
echo "<script>";
echo "
$(function(){
$('$type[name=$name]').trigger('change');
});
";
echo "</script>";
}
?>
The problem is that you are using "
which attempt to parse the variables in the string, if you switch to '
the $
of the jQuery won't be parsed and you can concat your variables with .
function trigger($type,$name) {
echo '<script>';
echo '
$(function(){
$(\'' . $type . '[name=' . $name . ']\').trigger(\'change\');
});
';
echo '</script>';
}