SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    HTML to External Javascript

    I have a piece of HTML;

    <area shape="rect" coords="0,0,120,30" HREF="javascript:chngPage(np[0]);chngMenu(nm[0])"
    onMouseover="newdesc(desc[1]); h('img01','sov[1]')"
    onMouseout="h('img01','sov[1]')">

    I want to put this into an external javascript file,
    Tried to use

    document.write('<area shape........

    but it stops working when I get to the h('img01',
    I know its because I'm using the single quote, but I'm having trouble transposing it to get rid of them.

    Any help?

    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to perform what's called escaping. Properly escaping the single quotes with the backslash (the escaping character in MANY scripting languages...) tells the code engine to ignore them as delimiters and treat them literally.
    Code:
    document.write('<area shape="rect" coords="0,0,120,30" HREF="javascript:chngPage(np[0]);chngMenu(nm[0])" onMouseover="newdesc(desc[1]); h(\'img01\',\'sov[1]\')" onMouseout="h(\'img01\',\'sov[1]\')">');
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Thanks Beetle

    Thanks, Now I understand what those \ are for
    found dblquot worked as well, which I should have tried ages ago!!
    Been on this one all day!

    document.write('<area shape="rect" coords="0,0,120,30" onclick=chngPage(np[0]);chngMenu(nm[0]) onMouseover=newdesc(desc[1]);h("img01","sov[1]")')
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  4. #4
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Escaping

    I have another one.....
    I'm trying to name 14 sounds, for rollover,
    I have done it the long-winded way, but now trying to condense it to an array.

    this is what I used to use..written 14 times

    document.write(
    '<embed name="s00" src="images/1.mp3" loop=false autostart=true hidden=true>')

    with

    <map name="marimba"> ...then written 14 times!!!!.....
    <area shape="poly" coords="23,9,24,165,37,164,34,9,23,9"
    onMouseOver="Sound('play','document.s1');alert(document.s1)">

    I use the alert at the end as my result needs to be [object]

    trying to condense it using a loop.....

    sndct=snd.length-10
    for (i=1; i<[sndct]; i++) {
    plsnd=["s"+i]
    document.write(
    '<embed name="plsnd" src="snd[i]" loop=false autostart=true hidden=true>');alert(plsnd+" "+snd[i])}

    again the alert here gives the right ouput, but the alert on the rollover gives undefined!!

    Still havent got the nack of this excaping
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if


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
  •