Using ASP And Javascript Together In ASP

Tips >> ASP

 



Using ASP And Javascript Together in ASP

WANTS TO MAKE SOFTWARE WITHOUT KNOWLEDGE OF ASP? CLICK HERE

 

JavaScript is an scripting language that is basically used for creating interactive features on webpages. It can be used to create menus, validate forms, swap images, or just about anything else you can think of to do on a webpage. If you have ever taken a look at Google Maps or Google's GMail service, you have an idea of what JavaScript is capable of today. Whereas, ASP stands for Active Server Pages. ASP (Active Server Pages) is an HTML pages that contain fixed scripts. ASP is a Microsoft Technology. ASP is a program that runs inside IIS (Internet Information Service).

In these tutorial, a regular HTML page with a small javascript code will be created , and we will use this javascript code to include in the page new information from a ".asp" file.

Example#1 :-

javascript.html  
<html>
<title>My page</title>
<body>

<script language="javascript" src="
javascript.asp"></script>

</body>
</html>
1
2
3
4
5
6
7
8
javascript.asp  
document.write ("hi") 1
Output :-
hi

Further Exxplanation :-

  • In the first file (javascript.html) we have include a javascript code in , and within the code the file name from which we will get information to complete our page (src: source). So that we are asking for information to complete our page (javascript.html) to a different page (JavaScript. asp). This time we have only include the file name, but we may use the complete url even from a different site (for example: https://www.xyz.com/javascript.asp).
  • In the second file (javascript.asp) we have include the information necessary to write in the document the word "hi". This time we have use ".asp" extensión for the second page even though other extensions are possible.

Example#2 :-
It explains a very simple banner rotator system

Our page is "mypage.html" and we are requesting information to complete it from "https://www.xyz.com/adrotator.asp" which may be located in the same or in a different site. The information provided by the second file will determinate the ad to be display in our page.

mypage.html  
<html>
<title>My page</title>
<body>

<script language="javascript" src="https://www.xyz.com/adrotator.asp"></script>

</body>
</html>
1
2
3
4
5
6
7
8
adrotator.asp  
<%
if session("ad")="" then
session("ad")=0
end if

if session("ad")=5 then
session("ad")=1
else
session("ad")=session("ad")+1
end if
%>

<% Select Case session("ad") %>
<% case 1 %>
document.write ("<A HREF=https://www.xyz1.com">)
document.write ("<IMG SCR=1.gif>")
document.write ("</A>")

<% case 2 %>
document.write ("<A HREF=https://www.xyz2.com">)
document.write ("<IMG SCR=2.gif>")
document.write ("</A>")

<% case 3 %>
document.write ("<A HREF=https://www.xyz3.com">)
document.write ("<IMG SCR=3.gif>")
document.write ("</A>")

<% case 4 %>
document.write ("<A HREF=https://www.xyz4.com">)
document.write ("<IMG SCR=4.gif>")
document.write ("</A>")

<% case 5 %>
document.write ("<A HREF=https://www.xyz4.com">)
document.write ("<IMG SCR=4.gif>")
document.write ("</A>")

<% End select %>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

Further Explanation :-

  • Lines 2-3. Each time a new visitor gets to
    "http :// www .xyz .com / adrotator.asp" a new session will be open, and by using the session method, we will define session("ad") value to 0. In case the visitor is not new, the value for session("ad") will exits, and that value will be keep.
  • Lines 6-10. The value for Session("ad") is increased by one unless that value is 5 (which is the maximum value allowed in this script)
  • Lines 13-34. By using Select_case the page will return the information necessary to display the appropiate ad at "mypage.html". The first time a visitor accesses our page the ad display will be the first one, the second time ad number two and so on. After 5 visits, the process will start again. We may easily increase the number of ads just by adding more obtions within Select_case and setting the maximum number from 5 to the new maximum in line 6.


Note :-
when writing the javascript code you must be very carefull: do not include brakets within the brakets in the javascript code
p.e.: Correct: document.write ("<A HREF=https://www.xyz4.com">)
Incorrect: document.write ("<A HREF="https://www.xyz4.com"">)
Correct: document.write ("<A HREF='https://www.xyz4.com'">)
You may include in the response as many lines like the ones above or any other javascript code.

 

 
E-mail : sales@virtualsplat.com
Phone : +91-9892413501

Whatsapp Icon +91-9967648641

Whatsapp Icon +91-9967648641