Jump to content

Confirm box before saving data


newphpbees

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

Archived

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

×
×
  • 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.