0

I am attempting to call a confirm popup from asp classic. Is there a way I can get this Javascript code to execute? It is currently not being called/executed. I need a popup to appear allowing the user to confirm if they want to clear an assignment or not. Thanks!

<%@ Language=VBScript %>
<!--#include file="content/securityheader.asp"-->
<!--#include file="connection.inc"-->
<!--#include file="connectionxref.inc"-->
<!--#include file="securityheader.asp"-->
<!--#include file="connectionSQL.inc"-->

<% 'SQL SECURITY CODE
    function dbencodeStr(str)
        thestr = trim(replace(str,"'","&#39;"))
        thestr = trim(replace(thestr,"""","&#34;"))
        thestr = trim(replace(thestr,"<","&lt;"))
        thestr = trim(replace(thestr,">","&gt;"))
        thestr = trim(replace(thestr,vbCRLF,"<BR>"))
        dbencodeStr = thestr
    end function
%>
<script language = "javascript"  runat="server">
function clearAssignment(assignmentID,relno,docrecid)
{
if (confirm("This is the last assignment for this relationship.")){
    window.location.assign("procclearassignmentprompt.asp?assignmentID="+assignmentID+"&relno="+relno+"&docrecid="+docrecid);
    }
}
</script>
<%
Server.ScriptTimeout=3600

'------------------------------
Function getName(str)
index = instr(str," ")
if index > 0 then
str = trim(mid(str,1,index))
end if
getName = str
End Function
'------------------------------

on error resume next

assignmentID = dbencodeStr(request.Querystring("assignmentID"))
docid = dbencodeStr(request.Querystring("docrecid"))
relno = dbencodeStr(request.Querystring("relno"))
thedate = now()

count = 1
'Check if this is the last assignment for relationship
strSQL = "select count(distinct reldocassignments.id) from reldocnotes inner join reldocassignments on reldocnotes.docid=reldocassignments.docid where relno = '"&relno&"' and reldocassignments.activeflag=1"
Set rs = objConnection.Execute(strSQL, ,adCmdText)
    arr = rs.GetRows()
    rows = UBound(arr,2)
    for i = 0 to rows       
        count = trim(arr(0,i))
    next
if count = 1 then
Response.Write "Calling =" & clearAssignment(assignmentID,relno,docrecid) & "."
else
    if docid <> "" Then
        ''''Close any open assignments for the document
        strSQL = "update RelDocAssignments set activeflag = 0, closedOn = getdate() where docid = '"&docid&"' and ID = '"&assignmentID&"';"
        Set rs = objConnection.Execute(strSQL, ,adCmdText)
    end if
Response.write(strSQL)


''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''

objConnection.close
set objConnection = nothing
objConnection2.close
set objConnection2 = nothing
objConnection3.close
set objConnection3 = nothing

Response.Redirect "relDetails.asp?relNo=" & relno
end if

%>
Count = <%=count%>
2
  • 3
    Server-side code runs in its entirety before the output is passed to your visitors browsers: it is not run interactively at all, so it doesn't mean anything to "call" a client-side function from server-side code. Fundamentally, all your .asp file does is generate text to the client. Commented Jul 27, 2015 at 23:28
  • 2
    He's actually calling a server-side function from server-side code. There's nothing happening on the client at all here. But yes, I think there's some confusion as to how server-side vs client-side works. Commented Jul 27, 2015 at 23:36

1 Answer 1

2

As others have implied, you need to have the confirm JavaScript client side,

So

  1. Remove the runat="server" for that JavaScript so it runs client side instead.

  2. To call that function client side change

    Response.Write "Calling =" & clearAssignment(assignmentID,relno,docrecid) & "."
    

    to

    Response.Write "<script language='javascript'>clearAssignment(" & assignmentID & "," & relno & "," & docrecid & ")</script>"
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.