38 users online (2 members and 36 guests)  


  Results 1 to 5 of 5

Related

  1. how to delete duplicate row fom table    Forum: Databases
    Replies: 0
  2. cant delete/add my schools    Forum: Myspace Forum
    Replies: 3
  3. Delete Gator    Forum: Webmaster Ethics
    Replies: 116
  1. #1
    RonB.'s Avatar
    New User

    Status
    Offline
    Join Date
    May 2002
    Location
    Near Chicago
    Posts
    8

    Confirmation box before delete

    <form method=POST action="Delete">
    .
    .
    .
    <input type="submit" name="Delete" value="Delete">
    </form>

    What I would like to do is have a confirmation box pop up when a user presses the "Delete" button and have a message along with 2 buttons on the box, "Yes" and "No".

    Thanks!

  2. #2
    Zaire's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Mar 2001
    Location
    Hamburg, NY
    Posts
    312
    Im not 100% sure on this, put stick this in your head

    Code:
    <script language="JavaScript">
    var cnf;
    var last;
    function cnf(msg)
    {
         cnf = confirm(msg);
         if(cnf) { 
              last = 'TRUE';
         }
    }
    function send(var)
    {
         if(last = "TRUE")
         {
             var.submit();
         }
    }  
    </script>
    Now, on your form, you should have

    <form name="form">

    and your submit button:

    <input type="Submit" Value="delete" name="delete" onclick="cnf('Are you sure you want to delete that?'); send(this);">

    This isn't tested, and Im new to javascript, so your gonna have to tell me the outcome

  3. #3
    RonB.'s Avatar
    New User

    Status
    Offline
    Join Date
    May 2002
    Location
    Near Chicago
    Posts
    8
    Thanks for trying but it doesn't seem to be working. Here is the entire code for that page. Does anyone see anything wrong?


    <script Language="JavaScript"><!--

    function y2k(number) { return (number < 1000) ? number + 1900 : number; }

    function ValProjectMaint(theForm)
    {

    if (theForm.ChgProject.value == "")
    {
    alert("Please enter a value for Title.");
    theForm.ChgProject.focus();
    return (false);
    }

    if (theForm.Longd.value == "")
    {
    alert("Please enter a value for Long Project Desc.");
    theForm.Longd.focus();
    return (false);
    }

    if (theForm.Longd.value.length > 250)
    {
    alert("You can not enter more than 250 characters in Long Description.");
    theForm.Longd.focus();
    return (false);
    }

    // checks if date passed is in valid yyyy/mm/dd format
    var checkSDate = theForm.StartDate
    var checkEDate = theForm.EndDate
    var reason = '';
    var sep = '-';

    if (checkSDate.value != "") {

    if (checkSDate.value.length == 10) {
    if (checkSDate.value.substring(4,5) == sep && checkSDate.value.substring(7,8) == sep) {
    var date = checkSDate.value.substring(8,10);
    var month = checkSDate.value.substring(5,7);
    var year = checkSDate.value.substring(0,4);

    var test = new Date(year,month-1,date);

    if (year == y2k(test.getYear()) && (month-1 == test.getMonth()) && (date == test.getDate())) {
    reason = '';
    }
    else {
    alert("Start date is invalid. Make sure you use format YYYY-MM-DD.");
    checkSDate.focus();
    reason = 'valid format but an invalid date';
    return (false);
    }
    }
    else {
    alert("Please use a date separator of ' - ' in date field.");
    checkSDate.focus();
    reason = 'invalid spearators';
    return (false);
    }
    }
    else {
    alert("Please use a 10 position date in the format of YYYY-MM-DD.");
    checkSDate.focus();
    reason = 'invalid length';
    return (false);
    }

    }

    if (checkEDate.value != "") {

    if (checkEDate.value.length == 10) {
    if (checkEDate.value.substring(4,5) == sep && checkEDate.value.substring(7,8) == sep) {
    var date = checkEDate.value.substring(8,10);
    var month = checkEDate.value.substring(5,7);
    var year = checkEDate.value.substring(0,4);

    var test = new Date(year,month-1,date);

    if (year == y2k(test.getYear()) && (month-1 == test.getMonth()) && (date == test.getDate())) {
    reason = '';
    }
    else {
    alert("End date is invalid. Make sure you use format YYYY-MM-DD.");
    checkEDate.focus();
    reason = 'valid format but an invalid date';
    return (false);
    }
    }
    else {
    alert("Please use a date separator of ' - ' in date field.");
    checkEDate.focus();
    reason = 'invalid spearators';
    return (false);
    }
    }
    else {
    alert("Please use a 10 position date in the format of YYYY-MM-DD.");
    checkEDate.focus();
    reason = 'invalid length';
    return (false);
    }

    if (checkEDate.value < checkSDate.value)
    {
    alert("End Date cannot be earlier than the Start Date.");
    theForm.ChgProject.focus();
    return (false);
    }

    }

    }
    //--></script> <script language="JavaScript">
    var cnf;
    var last;
    function cnf(msg)
    {
    cnf = confirm(msg);
    if(cnf) {
    last = 'TRUE';
    }
    }
    function send(var)
    {
    if(last = "TRUE")
    {
    var.submit();
    }
    }
    </script>

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Initial Screen</title>
    </head>
    <body bgcolor="#EAE8C8">
    <table>
    </table>
    <p align="center" style="margin-left: 0; margin-top: -2; margin-bottom: 10"><b>
    <font face="Verdana" color="#993333" size="4">Dynamic Systems Resources, Inc.
    </font></b>
    </p>
    <br>

    <table border="1" width="100%">
    <tr>
    <td width="100%" bgcolor="#0033CC"><b><font size="3" face="Verdana" color="#FFFFFF">Maintain
    Project</font></b></td>
    </tr>
    </table>
    <br>
    <table border="0">
    <p style="margin-top: 2; margin-bottom: 13">
    <tr>
    <td>
    <font color="#008080" face="Verdana"><b>
    <font size="3">Client:
    </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>
    </td>
    <td>
    </font>
    <font face="Verdana" size="3" color="#993333"><b>Butler</b>
    </font>
    <font face="Verdana">
    </font>
    </b>
    </td>
    </tr>
    </p>
    <p style="margin-top: 2; margin-bottom: 13">
    <tr>
    <td>
    <font color="#008080" face="Verdana"><b>
    <font size="3">Project:
    </font></b>
    </td>
    <td>
    </font>

    <font face="Verdana" size="3" color="#993333"><b>new project</b>
    </font>
    <font face="Verdana" size="2" color="#008080">
    </font>
    </td>
    </tr>
    </p>
    </table>
    <br><hr><br>

    <form method=POST action="Update" onsubmit="return ValProjectMaint(this)">
    <table border="0" cellspacing="0">
    <tr>
    <td> <p align="left">
    <font color="#008080" face="Verdana"><b>
    <font size="3">Project Description:
    </font></b></font>
    </p>
    </td>
    <td>
    <p align="left">
    <input type=text name=ChgProject size=25 maxlength=25 value="new project"> </p></td>
    </tr>
    <tr valign=top>
    <td> <p align="left">
    <font color="#008080" face="Verdana"><b>
    <font size="3">Long Project Desc:
    </font></b></font>
    </p>
    </td>
    <td> <p align="left"> <textarea name=Longd cols=50 rows=5 wrap=virtual>new project</textarea></p> </td>
    </tr>
    <tr>
    <td> <p align="left">
    <font color="#008080" face="Verdana"><b>
    <font size="3">Start Date: (YYYY-MM-DD)
    </font></b></font>
    </p>
    </td>
    <td> <p align="left"> <input type=text name=StartDate size=10 maxlength=10 value="2002-04-01"> </p></td>
    </tr>
    <tr>
    <td> <p align="left">
    <font color="#008080" face="Verdana"><b>
    <font size="3">End Date: &nbsp; (YYYY-MM-DD)
    </font></b></font>
    </p>
    </td>
    <td> <p align="left"> <input type=text name=EndDate size=10 maxlength=10 value=""> </p></td>
    </tr>
    <tr>
    <td> </td>
    <td>
    <table>
    <tr>
    <td>
    <input type="hidden" name="new" value="">
    <input type="hidden" value="DSR" name="Comp">
    <input type="hidden" value="Butler" name="Client">
    <input type=hidden value="Butler" name="SaveClient">
    <input type="hidden" value="new project" name="Project">
    <input type="hidden" value="Joe Schmo" name="Assoc">
    <input type="hidden" value="Vacation" name="Hrtyp">
    <input type=hidden value="Y" name="Entry">
    <input type="submit" value="Update" name="Update">
    </form>
    </td>
    <td>

    <form method=POST action="Delete">
    <input type="hidden" value="DSR" name="Comp">
    <input type="hidden" value="Butler" name="Client">
    <input type=hidden value="Butler" name="SaveClient">
    <input type="hidden" value="new project" name="Project">
    <input type="hidden" value="Joe Schmo" name="Assoc">
    <input type="hidden" value="Vacation" name="Hrtyp">
    <input type=hidden value="Y" name="Entry">
    <input type="submit" name="Delete" value="Delete" onclick="cnf('Are you sure you want to delete that?'); send(this);">
    </form>
    </td>

    </tr>
    </table>
    </td>
    </tr>
    </table>
    <br>
    <br>
    </body>
    </html>

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Try this -

    Code:
    <form method="post" action="blah.php" onSubmit="return confirm('Are you sure this is correct?');">
    In JS, its the 'return' that makes the difference. basically, you are saying 'If they answer yes, then submit the form, otherwise, just bail'.

    try it. I tested it and it worked.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  5. #5
    Zaire's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Mar 2001
    Location
    Hamburg, NY
    Posts
    312
    Im glad someone knows some JS ;P



Tags for this Thread