/    Sign up×
Community /Pin to ProfileBookmark

js vars as html links

Hi, I want to set a directory and an image name as a js variable and later call those vars as and html link. I am not doing this correctly, so I ask for help. Any advice is appreciated. Chuck
Here is a basic example.

<script type=”text/javascript” language=”javascript”>
var dirpath = ” [url]http://www.blah.com/images/[/url]“,
image1 = “de-01.jpg”;
</script>

<a href=”<script language=”javascript”>document.write(dirpath + image1);</script>”>image1</a>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@JonaAug 30.2004 — <i>
</i>&lt;script type="text/javascript"&gt;
//&lt;![CDATA[
document.write('&lt;a href="'+dirpath+image1+'" title="Image"&gt;Image&lt;/a&gt;');
//]]&gt;
&lt;/script&gt;
&lt;noscript&gt;
&lt;a href="images.html" title="See all images."&gt;Images&lt;/a&gt;
&lt;/noscript&gt;
Copy linkTweet thisAlerts:
@CharlesAug 30.2004 — 
  • * Do not use the CDATA indicator with HTML, and perhaps not at all. (The XHTML&trade; specification suggests that you limit yourself to external scripts to be compatable with HTML.)


  • * When you do use it with XHTML&trade; do not use it inside of the HTML style comments. (XHTML browsers are permitted to simply ignore everything inside of a comment.)


  • * Make sure that your page works for those of us that do not use JavaScript.
  • Copy linkTweet thisAlerts:
    @JonaAug 30.2004 — [font=trebuchet ms]I was using xHTML, Charles, not HTML. ? But thank you for letting me know about the comments, I wasn't sure if I should use them or not. ? [/font]
    Copy linkTweet thisAlerts:
    @CharlesAug 30.2004 — [i]Originally posted by Jona [/i]

    [B][font=trebuchet ms]I was using xHTML, Charles, not HTML. ? But thank you for letting me know about the comments, I wasn't sure if I should use them or not. ? [/font] [/B][/QUOTE]


  • * You can use them, I think, but you would have to put them inside the CDATA section.


  • * XHTML&trade; has a lot of features that make it incompatable with HTML. The CDATA section is one of them. And as the point of the comments is to make the SCRIPT element work with pre 1998 browsers, it doesn't make sense to use them with the CDATA section.


  • * There's a whole list of things that you need to do with XHTML&trade; to keep it compatable with HTML browsers (See http://www.w3.org/TR/xhtml1/#guidelines.) But since there is no added value to using XHTML&trade; over HTML and as one can observe much confusion between the two in the postings from beginners perhaps it's best that we all stop using it on this board.
  • Copy linkTweet thisAlerts:
    @JonaAug 30.2004 — [font=trebuchet ms]Thanks for the clarification, Charles. I'll keep that link handy, when in doubt, and I'll use HTML instead of xHTML to avoid confusion (unless the question involves xHTML).[/font]
    ×

    Success!

    Help @chucklarge spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...