Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to insert a variable in a window alert ?

Status
Not open for further replies.

leifoet

Technical User
Jan 31, 2016
203
0
0
BE
I want to insert a session variable: Session ("MemX") into a window alert - result of the variable => undefined
The variable in a non-alert application (response.write) does provide the desired result (= name).

<script>
<% member = Session ("MemX")%>

var name = member;

function myFunction ()
{alert ("Hi" + name + ", \ nBlaBlaBla");
}
</ script>
<script> myFunction (); </ script>

Is this the correct syntax?
Thanks for tips.
 
Nope.
ASP CANNOT show alert boxes to a client browser.
You would have to inject a javascript alert into the output stream.

Code:
<% response.write("<script language=" & chr(34) & "javascript" & chr(34) & ">alert('" & variable-goes-here & "');</script>") %>

Not tested by the way

OR you could set a javascript variable as the page loads.

Code:
<script language="javascript">
var session = '<%= Session["VALUE"] %>';
</script>

Then use that variable in a alert message box.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
I tried this version

<head>
<script language="javascript">
var name = '<%= Session["name"] %>';
</script>
</head>

with this result

Microsoft VBScript compilation error '800a0400'
Expected statement
/file.asp, line 95
= Session("name")%'>
^

what did I wrong ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top