Click to See Complete Forum and Search --> : Button onClick to conditionally open another page


moreta
07-24-2003, 08:56 AM
On a delete button I want to use window.confirm() before completing the button action. If confirm()=false, then the program will ignore the click. If confirm()=true, then I want to run another html program.

From examples on other conditional buttons I came up with INPUT TYPE="BUTTON" onClick=if (window.confirm("Delete this request?"))But have no idea how to finish, or whether this is a false start. I'd appreciate help.

Thank you,
moreta

Phil Karras
07-24-2003, 09:54 AM
Well, I'd use a function that returns true or false:

function DeleteIt() {
var Rtn = window.confirm("Delete this request?");
alert("Returning value: "+Rtn); // remove when done testing
return Rtn;
}

.
.
.
<!-- now use this in your button: -->
INPUT TYPE="BUTTON" onClick="return DeleteIt();"


See if that helps.

moreta
07-24-2003, 10:18 AM
Phil, thanks for trying to help me. I have a sinking feeling that I'm missing something very basic.

How do I pursue loading another page if the answer is true? That's my real problem. I started out with a function that used confirm(), but I don't know how to load my new page if the response is true.

Will I have to use a form and make this a submit button? There are no form controls in this html doc, excepting the buttons, which worked for history.back() without a form... but maybe that was cheating.:confused:

Thank you,
moreta

Phil Karras
07-24-2003, 10:23 AM
if (Rtn) {
document.location.href = NewURL;
}

where NewURL holds the new page URL you want to go to.

Best place for this is right in the little function I gave
you before right before "return Rtn;".

moreta
07-24-2003, 12:36 PM
That did it! :D I've never used document.location.href before. I finally put quotes around the URL, and it worked.

Thank you, Phil!
moreta