Jump to content

Recommended Posts

I am trying to implement a CONFIRMATION dialogue box before the processing of a form.

The dialogue box uses some variables from a previous script, so it seems that calling the confirmation box needs to be done through a function. And it seems that using a function to address the "action" is a tiny bit more complicated than just slapping a confirmation into the element.

My issue at this point is an inability to direct to the processing.php page

function confirm()  {
if(confirm("Are you sure you want to do this with $blah1 $blah2 $blah3 )== true)  {
window.location.href = "https://www.example.com";        //would actually be "processing.php"
} else {
return false;
     }
}

The browser shows an indication of 'thought' but will not advance to the next page (or an error page) - it simply refreshes.

Oddly, when I modified the end of the script to say this, it seemed to work

} else {
return false;

alert("bye");
   }
}

(but I don't understand why).

Answers? Solutions? Remedies? Explanations?  Please enlighten me.

 

Edited by phppup
Link to comment
https://forums.phpfreaks.com/topic/308101-something-odd-about-this/
Share on other sites

Assuming you have a form somewhere like

<form id="whatever" action="processing.php" method="post">

and aren't using a Javascript library, add an event listener for the form submission like

document.getElementById("whatever").addEventListener("submit", function(e) {
    if (!confirm("Are you sure you want to do this with $blah1 $blah2 $blah3")) {
        e.preventDefault();
    }
});

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.