Using options
Last updated
Was this helpful?
Was this helpful?
<?php $selected_color = get_option('text_color', $params['id']); ?>
<?php $colors = array('red', 'blue', 'green'); ?>
<script>
$(document).ready(function () {
$("#my_text_color").change(function () {
var data = {};
data.option_group = "<?php print $params['id'] ?>";
data.option_key = "text_color";
data.option_value = $(this).val();
$.post("<?php print api_url('save_option') ?>", data, function (resp) {
mw.reload_module_parent('#<?php print $params['id'] ?>');
});
});
});
</script>
<select id="my_text_color">
<option value="" <?php if (!$selected_color): ?> selected="selected" <?php endif; ?>>None</option>
<?php foreach ($colors as $color): ?>
<option value="<?php print $color ?>"
<?php if ($selected_color == $color): ?> selected="selected" <?php endif; ?>><?php print $color ?></option>
<?php endforeach; ?>
</select>