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!

call asp page when html page loads 1

Status
Not open for further replies.

PaulBricker

Programmer
Sep 25, 2002
3,554
US
I have an asp page that returns values from a database, and inserts them in a javascript routine that I got from DynamicDrive. The javascript routine displays a scrolling list of the 'contents' from the database table. I would like to display the results on an html page. Of course, I can display the scrolling list in the html page if I hardcode the 'contents' inside the javascript, but I want this to be a bit more dynamic so that I am able to pull the values right from the database.
I thought it would be easy but I'm not making much progress. A shove in the right direction would be great.

Thanks

Paul
 
If you write your ASP page to output JS code, you can use something like:
Code:
<script type="text/javascript" src="myASPpage.asp"></script>

Then you use your static Javascript to read the values in the dynamically created Javascript.

Lee
 
Yes, the asp page simple returns the values from the database and builds the results inside the javascript tags for the html page to read. Right now, if I use a link to call the asp page, it opens a new page and displays the results properly.

So this is what I tried in my html page

[blue]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>

<body>

<script type="text/javascript" src="
</body>
</html>[/blue]

but it did not return any results. I tried other versions of the path as well without luck.

Any thoughts?

Thanks

Paul
 
Well, I have only had limited luck. I did find a solution using iframes, but I would still like to see if I can't get it to work using your solution.
My asp page, named mytest.asp looks like this
Code:
<body>

<%

strQuery ="Select [Dept ID] FROM Dept"

Dim objConn, dbPath, strProvider, rst
  dbPath = "C:\WEBSITES\physplantdb\PysPlant2002.mdb"
  Set objConn = Server.CreateObject("ADODB.Connection")
  strProvider = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath
    objConn.Open strProvider

Set rst = Server.CreateObject("ADODB.recordset")
rst.Open strQuery, strProvider,3,3%><p><%
response.write "the number of records is " & rst.recordcount
%>
<p>
[b]<script type = "text/javascript">[/b]

var pausecontent2=new Array()


<%

    i=0
	   Do While Not rst.EOF %>
	  pausecontent2[<%= i%>]='<%= rst("Dept ID")%>';
	<%
		 i=i+1
		 rst.MoveNext
		 Loop%>
	[b]</script>[/b]

This renders the content for the js function.

My html page is
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<title>Untitled</title>
	
</head>
<body>


<script language="javascript" src="[URL unfurl="true"]http://physicalplant.williston.com/sampletestfiles/mytest.asp"></script>[/URL]


</body>
</html>

I have 2 questions. One, I assume that the script tags that I have in bold in the mytest.asp code are the tags that need to go away. Second, does the script tag on my html page go in the header or the body?

Thanks for any comments you have on this.

Paul
 
The dynamically created Javascript page should [red]ONLY[/red] have Javascript on it. The example you show above has a <body> tag, and may have other HTML in it.

I suggest putting the external JS file reference in the head.

Also, you need to Response.Write each element of the array rather than the way you have above.
Code:
Do While Not rst.EOF
  Response.Write "pausecontent2[" & i & "]='"
  Response.Write rst("Dept ID") & "';" & Chr(13) & Chr(10)
  i=i+1
  rst.MoveNext
Loop%>

Lee
 
It's a beautiful thing. I put the asp in a plain text editor without html tags, changes the code to response.write everything, and it is working just like it should.
Thanks very much for taking the time to get me straight on this. I appreciate it.

Paul
 
Hey Paul

I saw your post. And my problem is very similar to yours. I need to call a script src call from an asp page. Here are my sample files.

testdynamicCall.asp

<html>
<head>
<title>Hello</title>
</head>

<body>
Hello World!!
<script language="javascript" src="testdynamic.asp"></script>
</body>

</html>


testdynamic.asp

<% Response.Write("Hello Test") %>

The error I am getting is "; expected". Please can any one help me to come out of this. I tried all the possible ways I can. Your response with some sample code is much appreciated.

Thanks All.
 
Of course it doesn't work. What is the line:
Code:
Hello Test

supposed to do? You didn't have the Javascript document.write the value, you know. The actual internal JS equivalent of your code would be:
Code:
<script language="javascript">
Hello Test
</script>

Lee
 
Troll is saying you do something like the following in

testdynamic.asp

Rather than this:
Code:
<% Response.Write("Hello Test") %>

Do this:
Code:
<% Response.Write("document.write('Hello Test');") %>




[monkey][snake] <.
 
Thank u Troll and Monk. Thanks a lot for your quick response. It worked.

I have one more problem...

I have a default asp page which includes many other asp pages. I need one of the include asp page to get refreshed dynamically with in some time and not the whole default asp page. The include asp page that needs to be refreshed doesn't have any html code in it. It has just plain ASP code.

I knew we can refresh the page dynamically using the HTML META tag. But not sure how to do it in my case.

Please let me know if you have any suggestions.

Here is the include asp file:

<%
dim fso
dim fcoll
dim file
dim ts
dim intRndIndex
dim intCount
dim strPath
dim strFile

strPath = "/acsww/common/includes/HealthyTips/"

set fso = server.CreateObject("scripting.filesystemobject")
set fcoll = fso.GetFolder(server.MapPath(strPath)).Files

randomize
intRndIndex = int((fcoll.count) * Rnd)
if intRndIndex = (fcoll.count) then intRndIndex = intRndIndex -1


for each file in fcoll
if intcount = intrndindex then
exit for
end if
intcount = intcount + 1
next

set ts = file.OpenAsTextStream(1, -2)

Response.Write ts.ReadAll
set ts = nothing
set fcoll = nothing
set fso = nothing
%>

 
And here is my default.asp page

The code in the red is where the include page is being called.

Code:
<html>
	<head>
		<title>FightCancer.org :: Index Page</title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<script language="Javascript" src="/ACSWW/Common/Javascript/style_writer.js"></script>
		<script language="JavaScript" src="/ACSWW/Common/Javascript/mouse_over.js"></script>
		<script language="Javascript">
	var ptype = "x";
		</script>
	</head>
	<body marginheight="0" marginwidth="0">
		<table width="760" border="0" bgcolor="white" cellpadding="0" cellspacing="0" align="center"
			class="center" ID="Table1">
			<tr>
				<td><img src="/acsww/common/images/spacer.gif" height="1" width="3"></td>
				<td valign="top">
					<!--#include virtual="/ACSWW/Common/Includes/Developer/StdHeaderInc.asp"-->
					<%
	Dim RetVal
%>
<table width="754" border="0" cellpadding="0" cellspacing="0" style="margin-top: 2px;">
	<tr>
		<td rowspan="5" width="199" style="background-color: #E4EEF5;" valign="top">
			<div style="margin: 10px;" class="leftMenuText">
				<div align="center">
						<!--#include virtual="/ACSWW/Common/Includes/Developer/WelcomeMsgInc.asp"-->
				</div>
				<img src="/ACSWW/Common/Images/misc_bluebar.gif" height="3" width="170" align="center" vspace="10">
				<TABLE cellSpacing="0" cellPadding="0" width="179" border="0" ID="Table3">
					<TBODY>
						<%
							RetVal = oFcRuntime.HasPageOrOverride("/main/ACSWW/ActiveForLife/LeftSideContentIncludeAFL.asp",strRoot)
							if RetVal <> "Page Not Found" then
								%>
								<TR>
									<TD align="left">
										<%
										server.execute mid(RetVal,instr(1,UCASE(RetVal),UCASE(strRoot)))
										%>
									</td>
								</tr>

								<TR>
									<TD align="middle"><img src="/ACSWW/Common/Images/misc_bluebar.gif" height="3" width="170" align="center" vspace="10">
									</td>
								</tr>
								<%
							end if
							%>
						<%
							RetVal = oFcRuntime.HasPageOrOverride("/main/ACSWW/HomePageContent/LeftSideContent/leftside_gyst.asp",strRoot)
							if RetVal <> "Page Not Found" then
								%>
								<TR>
									<TD align="left">
										<%
										server.execute mid(RetVal,instr(1,UCASE(RetVal),UCASE(strRoot)))
										%>
									</td>
								</tr>

								<TR>
									<TD align="middle"><img src="/ACSWW/Common/Images/misc_bluebar.gif" height="3" width="170" align="center" vspace="10">
									</td>
								</tr>
								<%
							end if
							%>

						<TR>
							<TD align="left">
								<%
									RetVal = oFcRuntime.HasPageOrOverride("/main/ACSWW/HomePageContent/LeftSideContent/LeftSideInclude1.asp",strRoot)
									if RetVal <> "Page Not Found" then
										server.execute mid(RetVal,instr(1,UCASE(RetVal),UCASE(strRoot)))
									end if								
								%>
							</td>
						</tr>
						<TR>
							<TD align="middle"><img src="/ACSWW/Common/Images/misc_bluebar.gif" height="3" width="170" align="center" vspace="10">
							</td>
						</tr>						
						<TR>
							<TD align="left">
								<%
									RetVal = oFcRuntime.HasPageOrOverride("/main/ACSWW/HomePageContent/LeftSideContent/LeftSideInclude2.asp",strRoot)
									if RetVal <> "Page Not Found" then
										server.execute mid(RetVal,instr(1,UCASE(RetVal),UCASE(strRoot)))
									end if								
								%>
							</td>
						</tr>
						<TR>
							<TD align="middle"><img src="/ACSWW/Common/Images/misc_bluebar.gif" height="3" width="170" align="center" vspace="10">
							</td>
						</tr>
						<TR>
							<TD align="left">
								<%
									RetVal = oFcRuntime.HasPageOrOverride("/main/ACSWW/HomePageContent/LeftSideContent/LeftSideInclude3.asp",strRoot)
									if RetVal <> "Page Not Found" then
										server.execute mid(RetVal,instr(1,UCASE(RetVal),UCASE(strRoot)))
									end if								
								%>
							</td>
						</tr>
						<TR>
							<TD align="middle"><img src="/ACSWW/Common/Images/misc_bluebar.gif" height="3" width="170" align="center" vspace="10">
							</td>
						</tr>
						<TR>
							<TD align="left">
								<%
									RetVal = oFcRuntime.HasPageOrOverride("/main/ACSWW/HomePageContent/LeftSideContent/LeftSideInclude4.asp",strRoot)
									if RetVal <> "Page Not Found" then
										server.execute mid(RetVal,instr(1,UCASE(RetVal),UCASE(strRoot)))
									end if								
								%>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		<td rowspan="5" width="3"><img src="/ACSWW/Common/Images/spacer.gif" height="1" width="3" border="0"></td>
		<td width="552" colspan="2"><img src="/ACSWW/Common/Images/header1.gif" height="89" width="552" border="0" alt="Illustration"></td>
	</tr>
	<tr>
		<td colspan="2" height="3" width="552"></td>
	</tr>
	<tr>
		<td>
			<table cellpadding="0" cellspacing="0" border="0">
				[COLOR=red]<tr>
					<td style="background-color: #496BA8;" width="112"><img src="/ACSWW/Common/Images/misc_healthytip.gif" height="34" width="112" alt="Healthy Tip"></td>
					<td style="background-color: #496BA8;" width="440"><div class="healthytip"><script language="javascript" src="/ACSWW/Common/Includes/Developer/HealthTipInc.asp"></script></div></td>		
				</tr> [/color]
			</table>
		</td>
	</tr>			
	<tr>
		<td colspan="2">
			<div class="bodySpace">
				<table cellspacing="0" cellpadding="0" width="505" ID="Table5">
					<tbody>
						<tr valign="top">
							<td>
								<%
									RetVal = oFcRuntime.HasPageOrOverride("/main/ACSWW/HomePageContent/MainBodyContent/HomeBodyTL.asp",strRoot)
									if RetVal <> "Page Not Found" then
										server.execute mid(RetVal,instr(1,UCASE(RetVal),UCASE(strRoot)))
									end if								
								%>							
							</td>
							<td><img height="1" alt="" src="/ACSWW/Common/Images/spacer.gif" width="25" /></td>
							<td>
								<%
									RetVal = oFcRuntime.HasPageOrOverride("/main/ACSWW/HomePageContent/MainBodyContent/HomeBodyTR.asp",strRoot)
									if RetVal <> "Page Not Found" then
										server.execute mid(RetVal,instr(1,UCASE(RetVal),UCASE(strRoot)))
									end if								
								%>	
							</td>
						</tr>
						<tr valign="top">
							<td>
								<%
									RetVal = oFcRuntime.HasPageOrOverride("/main/ACSWW/HomePageContent/MainBodyContent/HomeBodyBL.asp",strRoot)
									if RetVal <> "Page Not Found" then
										server.execute mid(RetVal,instr(1,UCASE(RetVal),UCASE(strRoot)))
									end if								
								%>	
							</td>
							<td><img height="1" alt="" src="/ACSWW/Common/Images/spacer.gif" width="25" /></td>
							<td>
								<%
									RetVal = oFcRuntime.HasPageOrOverride("/main/ACSWW/HomePageContent/MainBodyContent/HomeBodyBR.asp",strRoot)
									if RetVal <> "Page Not Found" then
										server.execute mid(RetVal,instr(1,UCASE(RetVal),UCASE(strRoot)))
									end if								
								%>	
							</td>
						</tr>
					</tbody>
				</table>	
			</div>
		</td>
	</tr>
	<tr>
		<td colspan="2">

			<form method="post" action="[URL unfurl="true"]https://<%=request.servervariables("server_name")[/URL] %>/ACSWW/enewsletter/NewsletterConfirmation.asp">
<table cellpadding="0" cellspacing="0" border="0" width="552">
		<tr>
			<td rowspan="3" width="14" align="right"><img src="/ACSWW/Common/Images/misc_newsleft.gif" height="121" width="14" alt=""></td>
			<td width="523" valign="top" align="right"><img src="/ACSWW/Common/Images/misc_newstop.gif" height="26" width="523" alt=""></td>
			<td rowspan="3" width="22"><img src="/ACSWW/Common/Images/misc_newsright.gif" height="121" width="14" alt=""></td>
		</tr>
		<tr>
			<td width="523" bgcolor="#F7FAEC">
					<div class="newsBox">The free "<a href="/ACSWW/enewsletter/default.asp">BecauseWeCare</a>" newsletter brings you beneficial health tips, resources, and information. Sign up below to receive "<a href="/ACSWW/enewsletter/default.asp">BecauseWeCare</a>" by email.</div>	
					<img src="/ACSWW/Common/Images/spacer.gif" height="5" width="100"><br>		
					<table cellpadding="4" cellspacing="0" border="0"><tr><td><div class="label">Name:&nbsp;&nbsp;</div></td>
					<td><input type="text" id = "txtName" name="txtName" maxlength="" size="3" class="inputFieldhome"></td>
					<td><div class="label">Zip:&nbsp;&nbsp;</div></td>
					<td><input type="text" id = "txtZip" name="txtZip" maxlength="" size="3" class="inputFieldhome"></td>
					<td><div class="label">Email:&nbsp;&nbsp;</div></td>
					<td><input type="text" name="txtEmail" id = "txtEmail" maxlength="" size="3"  class="inputFieldhome"></div></td>
					<td><input type = "image" border="0"  src="/ACSWW/Common/Images/btn_go_green.gif"></td></tr></table>
												
			</td>
		</tr>
		<tr>
			<td width="523" bgcolor="#F7FAEC" valign="bottom"><img src="/ACSWW/Common/Images/misc_newsbottom.gif" height="11" width="523" alt=""></td>
		</tr>
	</table>
</form>		
		</td>
	</tr>
</table> 
					<!--#include virtual="/ACSWW/Common/Includes/Developer/StdFooterInc.asp"-->
					<!--#include virtual="/ACSWW/Common/Includes/Developer/ContrNavInc.asp"-->
				</td>
				<td><img src="/acsww/common/images/spacer.gif" height="1" width="3"></td>
			</tr>
		</table>
	</body>
</html>

Thank you all for your time
 
For you to want a refresh of ASP page data without refreshing the larger page, that will require AJAX. You may want to Google. It can get a little hairy.

[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top