How to properly use JavaScript confirm() in this case?

I have a textarea and a 3 buttons. Textarea allows user to put scripts in that area and those scripts will be printed above the closing tag on all pages (it is a simple plugin that I’m building). Buttons are: Change scripts, Add Scripts and Delete Scripts. All 3 works fine, but, now I want to prevent deleting scripts if someone accidentally clicks on Delete button, so I’m trying to implement a Javascript confirmation dialog. That part of the code is:



function delete_footer_confirmation() {
var confirmation = confirm(“All footer scripts will be deleted! nPress OK if you want to continue, or cancel to get back.”);
if (confirmation == true) {
<?php update_option(‘onixion_footer_scripts’,”); ?>
else {
<?php update_option(‘onixion_footer_scripts’,$this->post[‘footer_scripts’]); ?>

<div id=”setting-error-settings_updated” class=”updated settings-error
notice is-dismissible”>
<strong>Footer scripts have been deleted.</strong>

$header_scripts = get_option(‘onixion_header_scripts’,’none’);
$footer_scripts = get_option(‘onixion_footer_scripts’,’none’);


It shows the confirmation box when the button is clicked, but it doesn’t delete onixion_footer_scripts…

Without that script, if I just write


that worked, and the scripts were deleted. So, what can I do? How to solve this problem?

Read more here:: How to properly use JavaScript confirm() in this case?

Leave a Reply

Your email address will not be published. Required fields are marked *