Forum Moderators: open

Message Too Old, No Replies

Javascript outputs invalid markup

invalid markup output

         

beatsie

10:58 am on Jan 25, 2005 (gmt 0)

10+ Year Member



Hi all

first off i'm a beginner regarding Javascript.

What i'm trying to do is to get a javascript scrolling ticker script to output valid markup.

here is an example of what is output to the browser.

<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>
</script>

as you can see there are slashes beside quotation marks....i want to get rid of these.

here is where the javascript variable is set, php is also used here as database data is being used for ticker.

<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>

<script type="text/javascript" src="/js/marquee.js"></script>

</div>
<!-- ticker code -->
<div style="position:absolute; left:0px; top:160px; z-index:0;" onload="intializemarquee();">

Now when i remove the slashes from here, it stops working, the output to the browser is correct, but the ticker won't work.

the file marquee.js is called, then the function intializemarquee() is included in the onload for another <div>

here are the contents of marquee.js

//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

So can anyone recommend a way to stop the slashes in the variable string from being output to the browser

thanks in advance.

Bernard Marx

1:42 pm on Jan 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So can anyone recommend a way to stop the slashes in the variable string from being output to the browser

Maybe, but really this question is for the PHP forum [webmasterworld.com].