Hi there

I have a form which will delete items from a MySQL database. I'm having one problem though. I'd like to have a confirmation window popup and if yes is clicked then the php gets processed to delete the row out of the database.

Is it possible for javascript and php to interact together?

Recommended Answers

All 13 Replies

Absolutely. Try this.

<form action="whatever.php" method="POST" onsubmit="return confirm('Are you sure you want to submit this data?')">

Keep in mind, you'll still want to have some server side validation.

Thank you kindly for that buddy. I just have one question. Is there any way you can change the button options from saying "Ok" and "Cancel" to "Yes" and "No"??

Nope. You should write your own popup for that (with 2 buttons ie.,)

Nope. You should write your own popup for that (with 2 buttons ie.,)

I assume you'd do that with javascript then? Do you have any links I could look at? Sounds like it might come in handy at some point.

Well, I write my own page with 2 buttons to do required operation. Then I call that page using the following.

window.open(url,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width="300", height="200")

Here, url is the page that I want as popup.

Well, I write my own page with 2 buttons to do required operation. Then I call that page using the following.

window.open(url,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width="300", height="200")

Here, url is the page that I want as popup.

Oh cool. So basically you'd design a page that had the buttons on it and just pull it in with the above code in your "onSubmit" value in the form tag?

Yep. Or put the above code in a javascript function, and call that function with onclick event.

what if popups are disabled ?
i suppose you could check if the window is opened after calling the popup script but i would stick with the javascript confirm option as it is likely to cause you less grief.

hmm.. I would use confirm box too. But if you want to have custom buttons, thats the only way, a popup.

hmm.. I would use confirm box too. But if you want to have custom buttons, thats the only way, a popup.

personally i would float a DIV over the center of the page with two buttons in. Faking a popup as i rekon this would achieve sameeffect without popups (probably cuz i hate popup windows :D). but hey it depends how much trouble you want to go into to making two buttons look different.

Lol.. great idea though !

You guys rock....thanks for all your input.

Absolutely. Try this.

<form action="whatever.php" method="POST" onsubmit="return confirm('Are you sure you want to submit this data?')">

Keep in mind, you'll still want to have some server side validation.

Thanks for the quick fix to add user-verification before submitting the form. Saved me a lot of time!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.