Jump to content


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


Button Query

Recommended Posts

Hi Guys,

Instead of having two seperate buttons, I want to combine it to a single button.

[code]<INPUT TYPE="submit" NAME="btn_H_Submit" OnClick="return confirm('Click Yes to update database and send an email or No to update database only');"  VALUE="Enter Information">

First question, when I click on the button, the pop up shows 'OK' and 'Cancel'. How do I change it to 'Yes' and 'No'?

Second, I want the 'Yes' button to update the database and send an email while the 'No' will only update the same database only (no email will be sent). Can it be done? A sample code on template on this will help me greatly.


Share this post

Link to post
Share on other sites
You cannot change the buttons in the confirm dialog box. Unless you create your own custom popup window.

For your secound question yes it can be done. However you'll have to get javascript to submit the form and add a url parameter called send and assign the value of 1 to it. Then in your PHP script you check whether the url has the send paramerter and is equal to 1, you send the email. If its not there is is not equal to 1 you dont send the email.

I'll some code in a sec.

Also this is more of a javascript question so I'll move this to the correct forum

The html:
[code]< script type="text/javascript" >
// this function adds a url parameter which determins whether we send an email or not
function sendForm()
    // this gets our form
    // change yourFormName to the name of your form
    // if your form doesnt have a name set add
    // name="yourFormName" inside the form tag
    var form = yourFormName;

    // this variable holds TRUE if the user clicks OK or FALSE if the user clicks CANCEL.
    var sendEmail = confirm('Click Ok to update database and send an email or Cancel to update database only');

    // this si what adds the url parameter to the url
    // if the user clicks OK the we added ?send=1 to the url
    // if the user clicks CANCEL the we add send=0
    // this url parameter will be used by PHP to determin whether to send an email
    if(sendEmail) {
        form.action = form.action + '?send=1';
    } else {
        form.action = form.action + '?send=0';
< /script >

<form action="test.php" name="yourFormName" method="post">
  Forname: <input type="text" name="name" /><br />
  Surname: <input type="text" name="surname" /><br />
  <input type="submit" name="btn_H_Submit" onclick="sendForm()" value="Enter Information" />
Have a read of the comments above for more info on whats going one (the comments are the double backslashes(//))

The PHP code:

// update the database here
echo "Update the database here<br /><br /><br />";

// Remeber the send url parameter that gets set with the javascript.
// This is where we determin whether to send an email!
// This checks whether the send url parameter exists and it is equal to 1
// if it is we send the email.
if(isset($_GET['send']) && $_GET['send'] == '1')
  // send email

  echo 'send an email tooo!!!';


Share this post

Link to post
Share on other sites
Thanks wildteen88, I get the idea but I'm still a bit confused. Is there a sample tutorial or working code somewhere for reference?

Share this post

Link to post
Share on other sites
That is the working code. What errors are you getting. What bit are you confused about.

Share this post

Link to post
Share on other sites


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.