Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 15th, 2005, 01:12 PM
Authorized User
 
Join Date: Jun 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default DELETE BUTTON

Why is my delete button still deleting a record even when I hit cancel. Help please! Thanks. Here is my code:

JAVASCRIPT CODE

function before_delete()
{
     // PROMPTS REQUIRE TWO ARGUMENTS
    var task = document.frmPSATasks.tasknum.value;
    var agreement = document.frmPSATasks.agreementnum.value;
    var message = "Are you sure you want to delete task no " + task + " ?";
    var value_name = "";
    // PROMPTS RETURN TWO POSSIBLE VALUES
    // IF THE USER TYPES ESCAPE OR CLICKS CANCEL
    // THE RETURN VALUE IS NULL
    // IF THE USER TYPES RETURN OR CLICKS OK
    // THE INPUT LINE STRING IS RETURNED
    var return_value = confirm(message,value_name);

    if (return_value == false)
    {
        alert('Delete Cancelled!');
    }
    else
    {
        // Set the hidden variable to the task number
        document.frmPSATasks.tasknumhidden.value = task;
        document.frmPSATasks.agreementnumhidden.value = agreement;
        document.frmPSATasks.submit();
    }
}

AND FUNCTION CODE:

Function deleteTaskOrder()
    ' Local Recordset
    dim rsLocalDel
    ' Delete Contract
    Set rsLocalDel = server.CreateObject("adodb.recordset")
    SQL = "Select * from tblTasks where agreement_no = '" & strAgreementNum & "' and task_order = '" & strTaskNum & "'"
    Response.Write "We are deleting " & sql
    ' Run Query
    rsLocalDel.open SQL, cn, 0, 3
    ' Check to see if task exists
    if rsLocalDel.recordcount = 1 Then
    'if not rsLocalDel.eof Then
        ' deletes record
        With rsLocalDel
            .delete
            '.movenext
            .close
        End With
    Else
        ' Deleting more than one record, display error message
        Response.Write " Error: Attempting to delete " & rsLocalDel.recordcount &" records is not allowed. Please contact system administrator."
        'Response.Write "Error: Estimate Number " & strTaskNum & " no longer exists!"
    End If
    set rsLocalDel = nothing
End Function

select case btnAction
    case "Add"
        ' Add the task order
        if strAgreementNum <> "" and strTaskNum <> "" then ' Make sure user entered a value
            addTaskOrder()
           ' After the add, perform a search to reload agreement no :)
            searchAgreementNo
        end if
    case "Update"
        ' Update the task order
        if strAgreementNum <> "" then
            updateTaskOrder()
            ' After the update, perform a search to reload agreement no :)
            searchAgreementNo
        end if
    case "Delete"
        'Delete the task order
        if strTaskNum <> "" then
            deleteTaskOrder()
            ' After the delete, perform a search to reload agreement no :)
            'searchAgreementNo
        end if
    case ""
        ' Process the search
        if strAgreementNum <> "" then
            searchAgreementNo
        end if
   end select



slypunk
__________________
slypunk
 
Old June 15th, 2005, 01:18 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Where are you calling before_delete and where are you calling deleteTaskOrd?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old June 15th, 2005, 01:36 PM
Authorized User
 
Join Date: Jun 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 Where are you calling before_delete and where are you calling deleteTaskOrd?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
it is in the same file see the delete button is calling both the function deleteTaskOrder and the javascript function before_delete. I hope I explained this well

slypunk
 
Old June 15th, 2005, 01:40 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Is one running on the server and one on the client? Can you post the code for the button that triggers the action?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old June 15th, 2005, 01:44 PM
Authorized User
 
Join Date: Jun 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 Is one running on the server and one on the client? Can you post the code for the button that triggers the action?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
here is the button:
<input type="submit" name="btnAction" value="Delete" onclick="return before_delete();">

Function deleteTaskOrder()
    ' Local Recordset
    dim rsLocalDel
    ' Delete Contract
    Set rsLocalDel = server.CreateObject("adodb.recordset")
    SQL = "Select * from tblTasks where agreement_no = '" & strAgreementNum & "' and task_order = '" & strTaskNum & "'"
    Response.Write "We are deleting " & sql
    ' Run Query
    rsLocalDel.open SQL, cn, 0, 3
    ' Check to see if task exists
    if rsLocalDel.recordcount = 1 Then
    'if not rsLocalDel.eof Then
        ' deletes record
        With rsLocalDel
            .delete
            '.movenext
            .close
        End With
    Else
        ' Deleting more than one record, display error message
        Response.Write " Error: Attempting to delete " & rsLocalDel.recordcount &" records is not allowed. Please contact system administrator."
        'Response.Write "Error: Estimate Number " & strTaskNum & " no longer exists!"
    End If
    set rsLocalDel = nothing
End Function

' --- PROCESSING LOGIC STARTS BELOW

........


' Process the Add/Update/Delete/Search functions
btnAction = request("btnAction")
select case btnAction
    case "Add"
        ' Add the task order
        if strAgreementNum <> "" and strTaskNum <> "" then ' Make sure user entered a value
            addTaskOrder()
           ' After the add, perform a search to reload agreement no :)
            searchAgreementNo
        end if
    case "Update"
        ' Update the task order
        if strAgreementNum <> "" then
            updateTaskOrder()
            ' After the update, perform a search to reload agreement no :)
            searchAgreementNo
        end if
    case "Delete"
        'Delete the task order
        if strTaskNum <> "" then
            deleteTaskOrder()
            ' After the delete, perform a search to reload agreement no :)
            'searchAgreementNo
        end if
    case ""
        ' Process the search
        if strAgreementNum <> "" then
            searchAgreementNo
        end if
   end select

slypunk
 
Old June 15th, 2005, 01:49 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Ah, I see. You should return false from the confirmation method:

function before_delete()
{
 if (return_value == false)
    {
        alert('Delete Cancelled!');
        return false;
    }

HtH,

Without the false, the button still submits....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old June 15th, 2005, 01:54 PM
Authorized User
 
Join Date: Jun 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 Ah, I see. You should return false from the confirmation method:

function before_delete()
{
if (return_value == false)
    {
        alert('Delete Cancelled!');
        return false;
    }

HtH,

Without the false, the button still submits....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
AWESOME! THAT WAS IT! THANK YOU

slypunk
 
Old June 16th, 2005, 12:07 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sureshbabu Send a message via Yahoo to sureshbabu
Default

Hi,
 Why dont use "Confirm"... as below

dunction doDelete()
{
   if(Confirm("Do u want to delete the reocord?"))
   {
       return true;
   }
   else
   {
       return false;
   }

}

 
Old June 16th, 2005, 01:05 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Or even:

function doDelete()
{
   return confirm('Are you sure you want to delete this record?');
}


Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
php/mysql delete button and delete query dungey PHP Databases 17 April 11th, 2009 12:24 PM
How to disable GridView delete button for a user rao965 ASP.NET 2.0 Professional 0 May 9th, 2008 12:30 PM
confirmation from user from a delete button in the sansircar ASP.NET 1.0 and 1.1 Professional 1 January 25th, 2006 01:44 PM
How to delete the added button in outlook haiying Access VBA 0 June 10th, 2005 07:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.