Results 1 to 5 of 5

Thread: Javascript In ASP Nightmare

  1. #1
    Join Date
    Jun 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Javascript In ASP Nightmare

    I have an .asp page that I need to have a confirm message box returns false and not delete the record then goes back to the previous page or true as needed, delete the record and continues with the current page. My code, listed below, shows the correct popup message but continues to delete the record.

    Help Now Please!!!

    Ayomide.

    If NOT objRS.EOF Then
    msg="Employee ID Number: " +objRS("EmpLocatorID")+ " exists for " +objRS("EmpLastName")+ ", " +objRS("EmpFirstName")
    Response.Write "<" & "script language=javascript>"
    Response.Write "var msg = '"+msg+"';"
    Response.Write "var x=confirm(msg + '\nAre you sure want to delete this employee record?');"
    Response.Write "if(x==false)"
    Response.Write "{"
    Response.Write "window.history.go(-1);"
    Response.Write "}"
    Response.Write "<" & "/script>"
    objComm.CommandText = "DELETE from Listing WHERE EmpId = '"&strEmpID&"';"
    objComm.CommandType = adCmdText
    objComm.Execute intNoOfRecords
    End If

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Ayomide
    I have an .asp page that I need to have a confirm message box returns false and not delete the record then goes back to the previous page or true as needed, delete the record and continues with the current page.
    Using Javascript for such a critical operation is not a good idea, except perhaps in a controlled environment (such as a private intranet) where you can guarantee that all users will have the necessary support. It would be better to use a separate confirmation stage.

    If NOT objRS.EOF Then
    msg="Employee ID Number: " +objRS("EmpLocatorID")+ " exists for " +objRS("EmpLastName")+ ", " +objRS("EmpFirstName")

    [To-client output]

    objComm.CommandText = "DELETE from Listing WHERE EmpId = '"&strEmpID&"';"
    objComm.CommandType = adCmdText
    objComm.Execute intNoOfRecords
    End If
    As I'm reading this, it seems that you're confusing how server-side processing interacts with the client; you will have written the confirmation code, but deletion occurs immediately after the output has been written. The query will have been executed before the network will have relayed the response to the client. The confirmation either has to appear when the client initially requests deletion (that is, in the document that contains the delete command), or in a separate document that is shown between the deletion request and the document that performs that action.

    Response.Write "<" & "script language=javascript>"
    Might I ask: why are you performing a separate concatenation? It makes no difference client-side, and I doubt it does server-side either (but I could be wrong on the latter). In addition, the language attribute is deprecated - you should be using the (required) type attribute instead:

    HTML Code:
    <script type="text/javascript">
    Mike

  3. #3
    Join Date
    Jun 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Mike,
    Am I understanding you correctly, the javascript, which is client-side, needs to be place on the page that is calling the SQL delete code? If this is valid, then I have a greater challegne in calling two functions on the sending page that using the forms tag.

    I place my existing code into the asp page as a separate function calling it from within the form tag and it is not being recognized.

    Addititionally, I would like to reflect within the confirm message box the value the user entered in the specific text box.

    These web pages are being hosted on an Intranet.

    How do I get this accoplished?
    Last edited by Ayomide; 06-06-2005 at 08:26 PM. Reason: Incorrect statement

  4. #4
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Ayomide
    Am I understanding you correctly, the javascript, which is client-side, needs to be place on the page that is calling the SQL delete code?
    It would need to placed on the form or button that is used to initiate the deletion. For example:

    Code:
    function confirmDeletion() {
      return confirm('Are you sure want to delete this employee record?');
    }
    HTML Code:
    <input type="submit" name="operation" value="Delete"
     onclick="return confirmDeletion();">
    If this is valid, then I have a greater challegne in calling two functions on the sending page that using the forms tag.
    If you mean you have a function that is already called during submission (say, a validation function) then this fairly trivial to accomodate.

    If the existing function is just 'some function' that doesn't affect whether the form is sent, then just place a semicolon after the first function call:

    HTML Code:
    <form action="..." method="..."
     onsubmit="originalFunction(); return confirmDeletion();">
    If the existing function is a validation function, or something similar, then you can combine the return value with the confirmation function using the logical AND (&&) operator:

    HTML Code:
    <form action="..." method="..."
     onsubmit="return originalFunction() && confirmDeletion();">
    Addititionally, I would like to reflect within the confirm message box the value the user entered in the specific text box.
    That too is quite simple. Assuming the text box is named employeeID, then you could change the above to:

    Code:
    function confirmDeletion(message) {
      return confirm(message
       + '\nAre you sure want to delete this employee record?');
    }
    HTML Code:
    <form action="..." method="..."
     onsubmit="return originalFunction()
     && confirmDeletion('Employee ID: ' + this.elements.employeeID.value);">
    Mike

  5. #5
    Join Date
    Jun 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thank You

    Mike,
    Thank you very much for the help you gave me.
    I was able to get the last part of my web page completed due totally to the directions you rendered to me.

    Keep Teaching.

    Ayomide

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
  •