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

Using ASP commands inside Javascript

Status
Not open for further replies.

Parasu

Technical User
Mar 11, 2001
38
PH
Hi all,
Can I assign a value for an Application variable from inside Java Script?
Ex:
<language=JavaScript>
{
<% Application(&quot;var&quot;) = 1 %>
}

Is this possible? Or, in short, can I run ASP commands within Javascript?

Very Urgent
Kindly help
Thanx in advance

Parasuraman


Parasuraman
 
Hi Parasuraman,

Sure, since the Server only sends the page after processing all server scripting, it will not conflict with JS. But, it's good practice to centralize such declarations between the head or perhaps even better, above the html tag.

Hope to be of service.

Kristof
 
Hi Kristof,
Thanx for that. But, Im not very sure about the way to use it. Can u just show me how to use a statement, say response.write.

Thanx again for ur help

Parasuraman Parasuraman
 
Hi,

That would be something like this:

Code:
<!-- ASP declarations -->
<% Application(&quot;var&quot;) = 1 %>
<!-- end of ASP declarations -->
<html>
<head>
	<title>Write Application Value</title>
</head>
<BODY BGCOLOR=&quot;#FFFFFF&quot; MARGINWIDTH=&quot;0&quot; MARGINHEIGHT=&quot;0&quot; LEFTMARGIN=&quot;0&quot; TOPMARGIN=&quot;0&quot;>
<table border=&quot;0&quot; cellspacing=0 cellpadding=0>
	<tr><td>Value = <% Response.Write(Application(&quot;var&quot;))%></td></tr>
</table>
</body>
</html>

As i said, It's best to place declarations above, so the code stays as clear and readable as possible.
The response.write itself is placed in the body since that is where it is to be shown.

This method of ordering maximizes the readable for other (especially those with no ASP knowledge) people who work on the same pages as you.

It's not perfect, but it's the best you can get.

Gtz, B-)

Kristof
 
Thanx Kristof,
But, I wanted ASP code to be used within JAVASCRIPT. I don't find any JavaScript code in the sample?
Kindly clarfy

Parasuraman Parasuraman
 
Hi Parasu,

The following declares an application variable which is then available for display with a JS function.

Here goes:

Code:
<!-- ASP declarations -->
<% Application(&quot;var&quot;) = 1 %>
<!-- end of ASP declarations -->
<html>
<head>
	<title>Write Application Value</title>
	<script language=&quot;JavaScript&quot;>
		function doAlert() {
			vl = <%=Application(&quot;var&quot;)%>;
			alert(vl)
		}
	</script>
</head>
<BODY BGCOLOR=&quot;#FFFFFF&quot; MARGINWIDTH=&quot;0&quot; MARGINHEIGHT=&quot;0&quot; LEFTMARGIN=&quot;0&quot; TOPMARGIN=&quot;0&quot;>
	<A HREF=&quot;javascript:doAlert()&quot;>Show value</a>
</body>
</html>

You have to keep in mind that everything a client sees when he is browsing your pages can be modified and edited through ASP.

So, when you need a JS function, first make it work on its own. And then you can add the ASP code and fill the JS variables with the content of the ASP variables.

Does this clear what I mean? Sure hope it does! :)

Kristof
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top