Passing VB to javascript

R

Ruskin

I have seen a couple of web sites that detail how to do this, but seem to be
overlooking the obvious.... I have the following code and have tried
variations to get it working;


<!--#INCLUDE FILE="CommonFunctions.inc"-->
<%
'following is vb script....
if not MyFunction(check_field) then 'This function is in the
include
DisplayError("this failed")
else
ContinueProcess 'This sub routine is
in the include
end if

sub DisplayError(iErr)
%>
<SCRIPT language="javascript">
alert( <%= iErr %>);
history.go(-1);
</SCRIPT>
<%
end sub

%>

I want to pass different messages to the displayerror function, but just
can't seem to make it work... Any ideas?
 
A

Aaron Bertrand [MVP]

You're going to have to think about it slightly differently. The main
reason is you think all of this script interacts, when in fact, first the
ASP runs, then the client-side script runs. Let's look at it this way:

<%
sub showError(iErr)
response.write "<script>" & vbCrLf & _
"alert('" & replace(iErr,"'","\'") & "');" & _
"history.go(-1);" & vbCrLf & _
"</script>"
response.end
end sub

' play with making something true
' and somethingElse true

something = false
somethingElse = false

if something then
showError "this failed"
end if

if somethingElse then
showError "that failed"
end if
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top