Forum Moderators: coopster

Message Too Old, No Replies

message box to warn user

how to display a message box when user clicks a button

         

swati

3:56 pm on Oct 12, 2004 (gmt 0)

10+ Year Member



Hello,

I have a modify button on my page. The user can make changes on the page and click on "modify" to save changes in the database.

When the user clicks the button I want a message box to appear saying
" this will change data in the database. Do you want to go ahead?" with 'yes' 'no' options

Regards
Swati

kapow

5:05 pm on Oct 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think it is best to use JavaScript for warning messages. You might get a better answer here: [webmasterworld.com...]

Here is a JavaScript I think does what you want. (I didn't write this so if it doesn't work you should ask for a better one in the JavaScript forum.

YOUR LINK:
<a href="yourpage.htm" onClick="var flg=my_message(); return flg;"> Click Here</a>

PUT THIS IN YOUR HEAD TAG SOMEWHERE:
<script type="text/javascript">
function my_message() {
var flg=confirm('Your warning message here.\n\nClick OK to continue. Otherwise click Cancel.\n');
if (flg)return true;
return false;
} </script>

coopster

5:05 pm on Oct 12, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You mean with JavaScript on the client side? Use the onsubmit action handler to trigger a function that will do a window.confirm.
<script type="text/javascript"> 
function confirmModifications() {
if (window.confirm("This will change data in the database.
Do you want to go ahead?")) {
// Change the data...
} else {
// Don't change the data...
}
}
</script>

<edit>thanks kapow; looks like a two for one deal today :)</edit>

If you want something in PHP, you'll have to send an additional request back to the server to handle the confirmation.

SofterLogic UK

11:48 am on Oct 13, 2004 (gmt 0)

10+ Year Member



The other solution is of cousre to send theuser to a 2nd page to confirm - possibly with target=_blank set on the link