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!

Can ASP DB query be integrated into Javascript?

Status
Not open for further replies.

volcano

Programmer
Aug 29, 2000
136
HK
Hello, I have a question about ASP and Javascript. Thanks in advance.

I would like to show the database table status dynamically through the display of GIF in a web page. The planned method is I use a Javascript function to loop itself every minute to look for any records in the table. If records are found in TABLE, the image source will change to be another GIF (The web page won't refresh itself but is still able to show the latest status of the database table, which is the objective I want). The general codes are shown below. But it won't run successfully. Do you think what's wrong with my codes?

Thank you very much!
-----

<%
Dim adoCon
Dim rsTransaction
Dim strSQL
Set adoCon = Server.CreateObject(&quot;ADODB.Connection&quot;)
adoCon.Open &quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=&quot; & Server.MapPath(&quot;test.mdb&quot;)
Set rsTransaction = Server.CreateObject(&quot;ADODB.Recordset&quot;)
%>
<html>
<body>
<img name=&quot;status&quot; src=&quot;no_record.gif&quot;>

<script language=&quot;javascript&quot;>
nextt();

function nextt() {
<%
strSQL = &quot;SELECT * FROM TABLE&quot;
rsTransaction.Open strSQL, adoCon
if not rsTransaction.eof then
%>
document.images[&quot;status&quot;].src = &quot;has_record.gif&quot;;
<% end if %>
setTimeout(&quot;nextt()&quot;, 60000);
}

</script>

</body>
</html>
<%
set adoCon = nothing
rsTransaction.close
set rsTransaction = nothing
%>
 
this is not possible.

because javascript cannot access database.

so whenever a record changes javascript will not know about the change,

try adding the record and refresh the form, now it will work. Known is handfull, Unknown is worldfull
 
vbkris is right, it is not possible.
Just maybe a little more explanation for volcano to clarify the matter more:

Always remember that the javascript runs at the client (person viewing the webpage) and the asp/DB query code at the server. By the time the page loads at the client all the asp/DB query code have already been executed and finished (on the server). The only way to check if something have changed in the DB is to execute a query that checks the DB. For this to happen you have to go back to the server ie. refresh the page.

Hope this explaines why what you are trying to do is not possible. Office notice: The beatings won't stop until morale improves
 
Thank you very much for both of your help!

I will stop trying this method to meet my objective.

Now I have another idea. I am thinking of making use of LAYER. The source ASP page in the LAYER will refresh itself every minute to check the DB latest status (but the layer may be made invisible, or to be a tiny dot). Once new records are found in the table, this ASP page inside the LAYER will change the image source of its parent ASP page. In my imagination the parent page may not need to be refreshed....I haven't tried this (I am not very familiar with LAYERs indeed)...do you think it's possible to meet my objective?

Thanks again!
Volcano
 
nope layer cannot refresh without refreshing the page, try frames. Known is handfull, Unknown is worldfull
 
Hello, I mean if I add a statement like :
<META HTTP-EQUIV=&quot;Refresh&quot; CONTENT=&quot;60;URL=layer_page.asp>

in the source page inside the layer, could this meet my expectation?

Thanks again for your kind replies!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top