Jump to content

Recommended Posts

Hi...

 

I have a button to generate data or save all data in the database.

 

Now, I want that when i click the button to generate data it will not save all data, i want first appear an alert or confirm box asking if "Do you want to save data?" and i want it has a OK and Cancel...when the OK was pressed it will automatically save data and when the Cancel was pressed the alert/confirm box will closed?

 

 

Is it possible?

 

Can you give me an idea or example..But now i searching also for that.

 

 

here is my code:

<input type="button" name="GENERATE_DATA" value="GENERATE DATA" style="width: 200px;">

 

and i have a php file for saving data...

 

 

Thank you so much

Link to comment
https://forums.phpfreaks.com/topic/253453-confirm-box-before-saving-data/
Share on other sites

You need to have a form first, then do this

 

<script language="javascript">
function confirmMySubmit(theForm){
if(confirm("Ready?")){
	theForm.submit();
}
}
</script>


<form action="http://www.jotorres.com">
<input type ="button" name="GENERATE_DATA" value="GENERATE DATA" onclick="confirmMySubmit(this.form);">
</form>

I tried this code:

 

<input type="button" name="GENERATE_PAYROLL" value="GENERATE PAYROLL" style="width: 200px;" onclick="return confirm('Do you want to save the data')">

 

my problem now, I don't know where i can add the syntax or condition, that if I press OK it will save the data or if I press cancel it will close the confirm box.

 

 

Thank you

I resolved it using this code:

 

function generatepay(){
if (confirm("Are you sure do you want to generate payroll"))
        {          
        window.location="generate_payroll.php";


        } 

        else 
        { 
      window.location = "payroll_category.php";         
    

        } 
}

 

Thank you

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.