Included below is the current code that I am using:
<script type="text/javascript" >
function rightTopSidebarAd() {
document.write ("Text to test!");
}
</script>
<div style="border:3px solid #FF0000" id="rightTopSidebar">
</div>
<script type="text/javascript">
$j('#rightTopSidebar').text(rightTopSidebarAd());
</script>
Here I have a simple function rightTopSidebarAd()
that I would like to return or print the string "Text to test!". I would like the function to result in the content being placed inside the rightTopSidebar
element.
Currently it prints "Text to test!" just after the div because that is where the text()
method is placed. If I place the jQuery code above, then it is printed at that position.
Note: I can not place the jQuery code inside the div
because this is just a demo. In the original page all the div
elements will be spread around the webpage and I will have the jQuery functions stored in an external JavaScript file.
EDIT: Guys, my fault: I did show a simple function
function rightTopSidebarAd() {
document.write ("Text to test!");
}
To illustrate my problem, as you say a simple "return" will fix this problem, but the real function is not so simple, I'm trying to return a OpenX code, please advice me how to do it with this function:
function rightTopSidebarAd() {
document.MAX_ct0 ='{clickurl}';
var m3_u = (location.protocol=='https:'?'https://one.mydomain.com/www/delivery/ajs.php':'http://one.mydomain.com/www/delivery/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=15&target=_blank");
document.write ('&cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
document.write ("&loc=" + escape(window.location));
if (document.referrer) document.write ("&referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if ((typeof(document.MAX_ct0) != 'undefined') && (document.MAX_ct0.substring(0,4) == 'http')) {
document.write ("&ct0=" + escape(document.MAX_ct0));
}
if (document.mmm_fo) document.write ("&mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
document.write ("<noscript><a href='http://one.mydomain.com/www/delivery/ck.php?n=a8ed906c&cb={random}' target='_blank'><img src='http://one.mydomain.com/www/delivery/avw.php?zoneid=15&cb={random}&n=a8ed906c&ct0={clickurl}' border='0' alt='' /></a></noscript>");
}