Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Script Displaying Invalid Markup

    Hi all

    i am a beginner regarding javascript.

    i'm working with code someone else has written, its a scrolling ticker tape script.

    The problem im having is that the script outputs invalid markup to the browser like so:

    <a class=\"tickerfont\" onmouseover=\"this.style.color='#CC0000'\"; onmouseout=\"this.style.color='#330000'\";

    as you can see there are slashes in this output, which i want to remove.

    i have tried removing the slashes from where the javascript variable is set in the script like so.

    $tickernews .= '<a class="tickerfont" onmouseover="this.style.color='#CC0000'"; onmouseout="this.style.color='#330000'"; href="' .$urlpiece . 'fullnews.php3?tname=' . pg_Result ($resulttick, $row, randval) . '&amp;xname=' . pg_Result ($resulttick, $row, edartist) . '">' . strip_tags(pg_Result ($resulttick, $row, edtitle)) . '</a>.........' ;

    print 'var jscontent="' . $tickernews . '";';

    but this results in the script not working.

    i think its becuase javascript needs the slashes present to work with the variable.

    So...is there anyway to strip the slashes from the string in the javascript file while maintaining the functionality of the script.

    thanks in advance

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    $tickernews .= '<a class="tickerfont" onmouseover="this.style.color=\'#CC0000\'"; ....and so on

    Javascript accepts both type of quatation marks, but if the string is to be declared using one type, and if inside the string there is a need for the same type to be inserted as true string character, back slash is to be used:

    var foo = '<a class="tickerfont" onmouseover="this.style.color=\'#CC0000\'">';
    or
    var foo="<a class=\"tickerfont\" onmouseover=\"this.style.color='#CC0000'\">";
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for the reply Kor

    i followed your advice and only used backslashes with one type of quotation mark.

    unfortunately it resulted in the ticker not working

    however, when i examined the source of the page all the ticker data was there, minus the slashes that were causing the XHTML markup problem.

    here is where the variable jscontent is set using php

    Code:
    <script language="JavaScript" type="text/javascript">
    <?php
    
    $tickernews .= '<a class=\"tickerfont\" onmouseover=\"this.style.color=\'#CC0000\'\"; onmouseout=\"this.style.color=\'#330000\'\"; href=\"' .$urlpiece . '/fullnews.php3?tname=' . pg_Result ($resulttick, $row, randval) . '&amp;xname=' . pg_Result ($resulttick, $row, edartist) . '\">' . strip_tags(pg_Result ($resulttick, $row, edtitle)) . '</a>.........' ;
    
    print 'var jscontent="' . $tickernews . '";';	
    ?>
    
    </script>
    heres the full code for the marquee, in case you can spot anything that might help.

    Code:
    //marquee width (in pixels)
    var marqueewidth=570
    //marquee height (in pixels, pertains only to NS)
    var marqueeheight=17
    //marquee scroll speed (larger is faster)
    var speed=3
    //marquee contents
    var marqueecontents= jscontent;
    /************************************************************************************
    Value to preserve onload status
    ************************************************************************************/
    var oldOnLoad;
    oldOnLoad=window.onload;
    
    if (document.all)
    document.write('<div id="cmarquee01"><marquee scrollAmount='+speed+' style="width:'+marqueewidth+' ">'+marqueecontents+'</marquee></div>')
    
    function regenerate(){
    window.location.reload()
    }
    function regenerate2(){
    if (document.layers){
    setTimeout("window.onresize=regenerate",550)
    intializemarquee()
    }
    
    if (oldOnLoad!=null) oldOnLoad();
    }
    
    function intializemarquee(){
    document.cmarquee01.document.cmarquee02.document.write('<nobr>'+marqueecontents+'</nobr>')
    document.cmarquee01.document.cmarquee02.document.close()
    thelength=document.cmarquee01.document.cmarquee02.document.width
    scrollit()
    }
    
    function scrollit(){
    if (document.cmarquee01.document.cmarquee02.left>=thelength*(-1)){
    document.cmarquee01.document.cmarquee02.left-=speed
    setTimeout("scrollit()",100)
    }
    else{
    document.cmarquee01.document.cmarquee02.left=marqueewidth
    scrollit()
    }
    }
    
    window.onload=regenerate2
    thanks again

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    I don't know much about php so that I presume that there might be a missunderstanding between those two languages... I don't sense why you have open a javascript code space that insert php code lines... hm
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I don't know php too, but the first thing to do is to see the generated output (View-Source). Can you post the output?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes , mixing php and javascript seems strange, again the code was already in place on the site written by someone else.

    i think they are used them together as he was using php code to extract information from a database then use that data for the ticker.

    here is what the output looks like in the browser.

    Code:
    <div>
    <script language="JavaScript" type="text/javascript">
    var jscontent="<a class=\"tickerfont\" onmouseover=\"this.style.color='#CC0000'\"; onmouseout=\"this.style.color='#330000'\"; href=\"http://www.bla.com\">linkcontent</a>.........<a class=\"
    </script>
    
    <script type="text/javascript" src="http://www.mcd.ie/js/marquee.js"></script>
    
    </div>
    <!-- ticker code -->
    <div style="position:absolute; left:0px; top:160px; z-index:0;" onload="intializemarquee();">
    </div>
    then the javascript file with the script 'marquee.js' is called, then the function to start the marquee is called in the onload attribute of another <div>

  • #7
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mhoram
    i followed your advice and only used backslashes with one type of quotation mark.

    unfortunately it resulted in the ticker not working

    however, when i examined the source of the page all the ticker data was there, minus the slashes that were causing the XHTML markup problem.
    If the string is coming in from the database with the escape characters removed which is causing the javascript to break... You will need to escape the escape character to prevent the escape characters from escaping...

    IE: '<a class=\\"tickerfont\\" onmouseover=....

    .....Willy

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by mhoram
    here is what the output looks like in the browser.

    Code:
    <div>
    <script language="JavaScript" type="text/javascript">
    var jscontent="<a class=\"tickerfont\" onmouseover=\"this.style.color='#CC0000'\"; onmouseout=\"this.style.color='#330000'\"; href=\"http://www.bla.com\">linkcontent</a>.........<a class=\"
    </script>
    Is that the complete line of the output for the jscontent variable?
    Of course, minus the ... inside the string. The string looks fine with \" except that there is no closing double quote that will terminate the string.
    Code:
    var jscontent="<a ...>linkcontent</a>.........<a class=\"";
    BTW, there is no onload event handler for div tags.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #9
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    thanks for all the help and feedback people

    i tried your suggestion Willy Duitt, but it didnt work, despite your record amount of saying the word escape in a single sentence

    but it inspired me, i replaced all double quotations with single quotations and it solved by invalid markup probelem

    here's the code that worked.

    Code:
    $tickernews .= '<a class=\'tickerfont\' onmouseover=\'this.style.color=#CC0000\' onmouseout=\'this.style.color=#330000\' href=\'' .$urlpiece . '/fullnews.php3?tname=' . pg_Result ($resulttick, $row, randval) . '&amp;xname=' . pg_Result ($resulttick, $row, edartist) . '\'>' . strip_tags(pg_Result ($resulttick, $row, edtitle)) . '</a>.........';
    thanks glenngv i just pasted an incomplete string as an example..my fault.

    but yes, your of course right about the onload handler for div tags.

    so i put it in the <body> tags

    Code:
    <body onload="intializemarquee();">
    this gave me more problems as there are <a> tags in the ticker string. and it was called outside the <body> tags, which also is not valid markup.

    so basically i have just ditched the links in the ticker string, so it just scrolls as headlines rather than links.

    so the final string looks like this

    Code:
    $tickernews .= strip_tags(pg_Result ($resulttick, $row, edtitle)).'.........';
    so probably didnt need to worry about the quote problem at all

    not to worry....it was an interesting process

    thanks for all your help again everyone.


  •  

    Posting Permissions

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