Jquery read <?php echo get_option('value'); ?> and not the value

This is the php function present in function.php :

<?php
add_action('admin_menu', 'baw_create_menu');
function baw_create_menu() {
    add_menu_page('Bubbles', 'Bubbles', 'administrator', __FILE__, 'baw_settings_page');
    add_action( 'admin_init', 'register_mysettings' );
}
function register_mysettings() {
    register_setting( 'baw-settings-group', 'category' );
}
function baw_settings_page() {
?>
<div class="wrap">
<form method="post" action="options.php">
    <?php settings_fields( 'baw-settings-group' ); ?>
    <?php do_settings_sections( 'baw-settings-group' ); ?>
    <textarea style="width:400px" name="category"><?php echo get_option('category'); ?></textarea>

    <?php submit_button(); ?>
</form>
</div>
<?php } ?>

And I want to get the string :

  var category = "<?php echo get_option('category'); ?>";
  alert(category);

But the alert gives me my php code: <php echo get_option ('category');?> And not the string such as "banana"

Answers


var category = <?php echo json_encode(get_option('bulle_index_1')); ?> ;
alert( category );

http://www.php.net/json_encode


PHP cannot be parsed in a .js file. You need to create a function in your .js file and pass in the string returned from PHP:

function fromPHP(phpString) {
    var category = phpString;
    alert(category);
}

In your .php file:

fromPHP(<?php echo json_encode(get_option('bulle_index_1')); ?>);

Need Your Help

Missing Mysql-Opimization

mysql optimization status

I have precomputet some similarities (about 70 million) and want to find the similarities from one track to all other tracks. I only need the top-100-tracks that have the highest similarities. For my

VBA: Regex and Dir() function questions

regex vba excel-vba directory excel

I wrote a simple script, using VBA. (I need to optimize some work with excel).