Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 15th, 2005, 01:12 PM
Authorized User
 
Join Date: Jun 2003
Location: Neverland, FL, USA.
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
  #2 (permalink)  
Old June 15th, 2005, 01:18 PM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,052
Thanks: 80
Thanked 1,581 Times in 1,558 Posts
Default

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

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
  #3 (permalink)  
Old June 15th, 2005, 01:36 PM
Authorized User
 
Join Date: Jun 2003
Location: Neverland, FL, USA.
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
  #4 (permalink)  
Old June 15th, 2005, 01:40 PM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,052
Thanks: 80
Thanked 1,581 Times in 1,558 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.
  #5 (permalink)  
Old June 15th, 2005, 01:44 PM
Authorized User
 
Join Date: Jun 2003
Location: Neverland, FL, USA.
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
  #6 (permalink)  
Old June 15th, 2005, 01:49 PM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,052
Thanks: 80
Thanked 1,581 Times in 1,558 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.
  #7 (permalink)  
Old June 15th, 2005, 01:54 PM
Authorized User
 
Join Date: Jun 2003
Location: Neverland, FL, USA.
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
  #8 (permalink)  
Old June 16th, 2005, 12:07 AM
Friend of Wrox
 
Join Date: Sep 2004
Location: Hyderabad, Andhra Pradesh, India.
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;
   }

}

  #9 (permalink)  
Old June 16th, 2005, 01:05 AM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,052
Thanks: 80
Thanked 1,581 Times in 1,558 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.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.