I want to add php code within jquery. I know that the file then cannot be saved as a js file but must be saved as a php file to execute the php code. If we save it as a php file then it can also not be enqueued within function.php.
jQuery(document).ready(function() {
jQuery('#a, #b').change(function () {
var $this = jQuery(this), // Get a handle on the checkbox we just clicked.
$a = jQuery('#a'),
$b = jQuery('#b'),
$c = jQuery('#c'), // Get a handle on the textbox.
$d = jQuery('#d'), // Get a handle on the textbox.
$e = jQuery('#e'), // Get a handle on the textbox.
$f = jQuery('#f'), // Get a handle on one of our default values.
$g = jQuery('#g'); // Get a handle on one of our default values.
if ($this.attr('id') == 'a' && $this.is(':checked')) {
// Clicking checkbox a will add the content of c and f and place it in e
// It will also uncheck checkbox b.
$e.val( <?php echo stripslashes(get_option('m')); ?> );
$b.removeAttr('checked');
} else if ($this.attr('id') == 'b' && $this.is(':checked')) {
// Clicking checkbox b will add the content of d and g and place it in e
// It will also uncheck checkbox a.
$e.val( <?php echo stripslashes(get_option('m')); ?> );
$a.removeAttr('checked');
} else {
$e.val('');
}
});
});
So how can I add php within my jquery and integrate it within my function.php theme file. Also please be noted that the php echo will return a javascript code so will it be possible that this code will be just added as a text and not echo as an executed code. Please help.