SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Alert/Confirm box for saving data

    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:
    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

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    In the most simple form you can use a confirm declaration which by default has an OK and CANCEL button, see the below example:

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

  3. #3
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SgtLegend View Post
    In the most simple form you can use a confirm declaration which by default has an OK and CANCEL button, see the below example:

    HTML Code:
    <input type="button" name="GENERATE_DATA" value="GENERATE DATA" style="width: 200px;" onclick="return confirm('Do you want to save the data')">
    Yes, I tried also that code..But it has no condition that if i press OK it will save data and if i press cancel it will closed the confirm box.

    Thank you

  4. #4
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Does your button reside in a <form> element? If it doesn't it would be best to have it wrapped in one as the example above will either cancel or allow the data to be sent, if you cannot have a form running for any reason another way would to create a function that checks the confirm status and then connects to your PHP script if the given button selection is OK.

  5. #5
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I resolved it using this code:

    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

  6. #6
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Glad you worked it out bud

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,788
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    I resolved it using this code:
    Just remember that as that dialog box is intended for debugging that it also has an option for turning off JavaScript in some browsers and turning off all further debugging type dialog boxes in some others.

    If you don't want to present people with that third option in the browsers that make the debugging tools more useful by providing them then you should create your own lightbox form instead.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how can I create a lightbox?I'm nort familiar on that..

    Thank you


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •