Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: insert dynamic values into javascript variable

  1. #1
    Join Date
    May 2006
    Posts
    98
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default insert dynamic values into javascript variable

    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

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    var tip6 = '<&#37;=rsCard("xxxxxxxxxx")%>';
    ... unless the returned code contains an apostrophe, in which case you'll have to escape it in the ASP.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    May 2006
    Posts
    98
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default

    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
    Last edited by rich1234; 07-28-2007 at 09:30 PM. Reason: adding

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    May 2006
    Posts
    98
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default

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

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Indeed I do.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    May 2006
    Posts
    98
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default

    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

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You need that whole bit of code:
    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    May 2006
    Posts
    98
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default

    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

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I live at http://www.twey.co.uk/ if you want to link to me. It's being reworked as well.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •