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

Asp and JS interaction

Status
Not open for further replies.

Seeff

Programmer
Dec 2, 2002
33
IL
Hi to all the experts,

I have two frames.The first one has thumbnails. I have managed to get the second frame to change to the larger picture with the "onmouseover" event (JS). So far, ok.

The JS script looks like this:
function rollIt(whichPic)
{
top.picframe.document.images.pic1.src = whichPic;
}

The parameter passed (whichPic) is something like this "\pics\pic1.jpg".

I would like to change some text next to the large picture with some data from a database. The sql key is the picture name (pic1).

When and where do I perform the sql (select details where picname="pic1.jpg") and how and where do I update the text?

Thanks for your help,
Laurence
 
You have to use a <div> or <span> to put the original text in, then use document.getElementById(divname).innerHTML to change the text. This has been covered before, so if you do a search on innerHTML you should find some good examples.

If you want to see it used as a slide show, here's a simple one on a free site:


Lee
 
Thanks for your input Lee. I guess I need to clarify the question.

I have to query the database and send two parameters to the javascript - the jpg filename AND the result of the sql.

I have no clue as to how to configure the onmouse event to send two parameters to the javascript. It currently looks like this:

<a onmouseover="javascript:rollIt('/Pics/r342_grey.jpg')>
How do I take r342_grey.jpg, query the database with this and THEN send TWO parameters to the jscript?

Thanks again,

Laurence
 
If you're using 2 frames, then clicking on a thumbnail in one could reload the frame with the other picture in it, passing the photo parameter in the URL so the other frame can process the request and get the information from your data file. You'll have to reload the web page in that frame completely, though, since the server and client can't communicate except through some kind of submit.

Lee
 
basically you would want to output that data from the recordset at the same time as your outputting the image names, before the page loads.
Add an extra argument to your javascript function and then do your recordset call before you output the rollover link. Output your ASP variable/recordst value/whatever where you would normally type in a second argument. Kinda like this:
Code:
<html>
<head>
<script language="javascript">
function myFunc(a,b){
   alert("a is " + a + " and b is " + b);
}
</script>
</head>
<body>
<%
Dim myConn, myRecordset, myValue
...etc etc do your select, pull back your recordset, set your value
%>
<a onmouseover="javascript:rollIt('/Pics/r342_grey.jpg'[highlight],'<%=myValue%>'[/highlight])>

If you need to output multiple links then you could fairly easily pull back all of the necessary values and loop through them, outputtingthem with the correct pictures. In fact, if your picture name is in the database then you could pull both back and build the links dynamically with each matching picture name and value.

As far as the javascript is concerned, I think trollacious had you covered above.

-T

barcode_1.gif
 
basically you would want to output that data from the recordset at the same time as your outputting the image names, before the page loads.
Add an extra argument to your javascript function and then do your recordset call before you output the rollover link. Output your ASP variable/recordst value/whatever where you would normally type in a second argument. Kinda like this:
Code:
<html>
<head>
<script language="javascript">
function rollit(a,b){
   alert("a is " + a + " and b is " + b);
}
</script>
</head>
<body>
<%
Dim myConn, myRecordset, myValue
...etc etc do your select, pull back your recordset, set your value
%>
<a onmouseover="javascript:rollIt('/Pics/r342_grey.jpg'[highlight],'<%=myValue%>'[/highlight])>

If you need to output multiple links then you could fairly easily pull back all of the necessary values and loop through them, outputtingthem with the correct pictures. In fact, if your picture name is in the database then you could pull both back and build the links dynamically with each matching picture name and value.

As far as the javascript is concerned, I think trollacious had you covered above.

-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top