Decarn Posted August 22, 2006 Share Posted August 22, 2006 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">[/code]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.Thanks. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 22, 2006 Share Posted August 22, 2006 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 forumThe html:[code]< script type="text/javascript" >// this function adds a url parameter which determins whether we send an email or notfunction 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" /></form>[/code]Have a read of the comments above for more info on whats going one (the comments are the double backslashes(//))The PHP code:[code]<?php// update the database hereecho "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!!!';}?>[/code] Quote Link to comment Share on other sites More sharing options...
Decarn Posted August 23, 2006 Author Share Posted August 23, 2006 Thanks wildteen88, I get the idea but I'm still a bit confused. Is there a sample tutorial or working code somewhere for reference? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 23, 2006 Share Posted August 23, 2006 That is the working code. What errors are you getting. What bit are you confused about. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.