Jump to content

something odd about this


phppup

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.

 

Link to comment
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();
    }
});

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.