Log in

View Full Version : insert dynamic values into javascript variable



rich1234
07-28-2007, 10:27 AM
Hi,

I have a javascript tooltip. like this

<a href="http://www.xx.com/" id="tip7">xx</a>

with a javascript variable like this in the head or attached externally

var tip6 = '<img src="a/6.jpg"><div class="tp2">pppppp</div>';

I want to insert the var tip dynamically through a field in my database interface with a asp code like this.

<&#37;=rsCard("xxxxxxxxxx")%>

Anyone know how I can do away with the external var tips and have them generated from the database interface.

Thanks
Richard

Twey
07-28-2007, 01:45 PM
var tip6 = '<&#37;=rsCard("xxxxxxxxxx")%>';... unless the returned code contains an apostrophe, in which case you'll have to escape it in the ASP.

rich1234
07-28-2007, 08:21 PM
Dear Twey, That worked a treat. I was though hoping there was some way to do away with the need to declare all the var tips, maybe by an <a> tag mouseover do this <&#37;=rsCard("xxxxxxxxxx")%> and mouse off do this <%=rsCard("xxxxxxxxxx")%>. As the asp generates all the links from the database I thought it could do the same with the tip variables. Would that work or do you still have to declare all of the variables?


The original tooltip came like this
<a href="javascript: //" onmouseover="doTooltip(event,tipImgTxt)" onmouseout="hideTip()">images and text</a>.
with variables like this
var tipImgTxt = '<img src="images/sm-duck.gif" width="90" height="44" alt="" border="0"><div class="tp2">Images and text can go together in a tooltip.</div>';

Is it possible to write something like
<a href="javascript: //" onmouseover="doTooltip(event,<%=rsCard("xxxxxxxxxx")%>. )" onmouseout="hideTip()">xxxxxx</a>.

If so what would you declare for <%=rsCard("xxxxxxxxxx")%>. Would it be some unique identifier, or could it be the thumbnail image field
<%=Server.URLPathEncode(rsCard("ThumbnailURL"))%>

Thanks for your help.
Richard

Twey
07-28-2007, 08:39 PM
Yes. But again, you need to put it in quotes, and your ASP needs to ensure that no illegal characters are part of that output.

rich1234
07-28-2007, 09:10 PM
Do you mean like this
<a href="javascript: //" onmouseover="doTooltip(event,'<&#37;=rsCard("xxxxxxxxxx")%>' )" onmouseout="hideTip()">xxxxxx</a>
thanks
Richard

Twey
07-28-2007, 09:18 PM
Indeed I do.

rich1234
07-28-2007, 09:58 PM
Dear twey, I think its almost there. The popupworks almost work. viewsource gives me.

<a onmouseover="doTooltip(event,'images/sharlasmall.jpg' )" onmouseout="hideTip()" href="http://www.fallahian.com" target="_blank">Sharla Fallahian</a>

and all I see in the tooltip is the text for example... images/sharlasmall.jpg, not the actual image. I was able to see the image when the same asp include was part of the tip variable in the head, but not now.

The code I have in the link is.

<a onmouseover="doTooltip(event,'<&#37;=Server.URLPathEncode(rsCard("ThumbnailURL"))%>' )" onmouseout="hideTip()" href="http://<%=rsCard("DefaultHeadline")%>" target="_blank"><%If Trim(rsCard("Author"))<>"" Then%> <%=rsCard("Author")%><%End If%></a>


There must be some small thing missing.
Any ideas.
Thanks
Richard

Twey
07-28-2007, 10:49 PM
You need that whole bit of code:
<a onmouseover="doTooltip(event,'<img src=&quot;<&#37;=Server.URLPathEncode(rsCard("ThumbnailURL"))%>&quot; width=&quot;90&quot; height=&quot;44&quot; alt=&quot;&quot; border=&quot;0&quot;><div class=&quot;tp2&quot;>Images and text can go together in a tooltip.</div>' )" onmouseout="hideTip()" href="http://<%=rsCard("DefaultHeadline")%>" target="_blank"><%If Trim(rsCard("Author"))<>"" Then%> <%=rsCard("Author")%><%End If%></a>Yuck, ASP.

rich1234
07-28-2007, 11:14 PM
Dear Twey, All I can say is thanks a million. I have had a link to dynamic drive for a year now for wok john helped me with. If you have another site I will happily add a link. My site is wotartist and this is for a revamp.
Thanks again
Richard

Twey
07-28-2007, 11:48 PM
I live at http://www.twey.co.uk/ if you want to link to me. It's being reworked as well.

rich1234
07-29-2007, 10:02 AM
done
thanks
Richard