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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

include asp string in javascript alert 2

Status
Not open for further replies.

lorca

Technical User
Dec 20, 2005
64
GB
hello

in my asp i have a variable called Enquiry, which holds a value.
I'd like, on the onlick of the save button to return the Enquiry variable in an alert ?

how can i ?

thanks
rob
 
It effectively means hard-coded it at loadtime.
[tt] onclick="alert('<%=Enquiry%>')"[/tt]
If you mean something else, it won't do.
 
Have you tried it like this?
Code:
<input type="button" name="mybutton" value="Save" onclick="alert('<%=Enquiry%>');">

It's just a matter of inserting the asp value where you need it and you do that by using the asp script tags with the = before the variable.

At my age I still learn something new every day, but I forget two others.
 
thanks

getting unterminated string constant error now

Code:
Response.Write "  <input type=submit name=SAVE onclick=""alert('<%=Enquiry%>')""  value=SAVE>
 
>Response.Write " <input type=submit name=SAVE onclick=""alert('<%=Enquiry%>')"" value=SAVE>
[tt]Response.Write " <input type=[red]""[/red]submit[red]""[/red] name=[red]""[/red]SAVE[red]""[/red] onclick=""alert('<%=Enquiry%>')"" value=SAVE>[red]"[/red][/tt]
 
Sorry a retake.

[tt]Response.Write " <input type=[red]""[/red]submit[red]""[/red] name=[red]""[/red]SAVE[red]""[/red] onclick=""alert('[red]" & Enquiry & "[/red]')"" value=[red]""[/red]SAVE[red]""[/red]>[red]"[/red][/tt]

 
still same error

Code:
Microsoft VBScript compilation  error '800a0409'

Unterminated string constant

/CCCu_PROCESSENQUIRY_AbanVehicles.ASP, line 724

Response.Write "  <input type=""submit"" name=""SAVE"" onclick=""alert('<% =Enquiry
----------------------------^
 
Since you are doing a response.write on the string directly from ASP do it like this:
Response.Write " <input type=""submit"" name=""SAVE"" onclick=""alert('" & Enquiry & "');"

If you are inserting the asp value into the HTML you would use the asp script tags but since you are already working in asp you just concantenate the value onto the string.



At my age I still learn something new every day, but I forget two others.
 
Whoops, missed the tail end there. Here is the full string.
Code:
response.Write "  <input type=""submit"" name=""SAVE"" onclick=""alert('" & Enquiry & "');"">"

I neglected to close off the tag and quotes. :)


At my age I still learn something new every day, but I forget two others.
 
great thanks

I am getting a similar problem now with

Code:
Response.Write "<script>location.href = ctsURL("Summary.asp") & "&EnquiryID=" & Enquiry & 
"&target=Summary.asp?id2=" & request("id2")</script>"

i put ""Summary.asp"" which seemed to sort that part but then i get invalid character for the ?

thanks for your help
 
What is ctsURL() before somebody send you to asp forum?
 
don't know...............3rd party software, hence all the response.writes i have to do !
 
don't know...............3rd party software
Even 3rd party software has to document its function...

Try this, otherwise you really have to go to asp forum for vbs syntax.
[tt]
Response.Write "<script>location.href = [red]" & [/red]ctsURL("Summary.asp") & "&EnquiryID=" & Enquiry & "&target=Summary.asp[red]" & escape("[/red]?id2="[red])[/red] & [red]escape([/red]request("id2")[red]) & "[/red]</script>"
[/tt]
(no line-break).
 
Or you may have to further enclose the right-hand side by quotes like this.
[tt]
Response.Write "<script>location.href = [red]""[/red]" & ctsURL("Summary.asp") & "&EnquiryID=" & Enquiry & "&target=Summary.asp" & escape("?id2=") & escape(request("id2")) & "[red]""[/red]</script>"
[/tt]

 
thank you very much ! works a treat

re. 3rd party software - not this one !
i guess you get what you pay for...............
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top