Welcome to WebmasterWorld Guest from 54.163.68.15

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

echo back javascript problem

   
7:07 pm on Oct 15, 2007 (gmt 0)

10+ Year Member



I'm trying to echo a javascript. I think I've commented out everything, but it's causing errors. Is there a better way to do this?

echo "<script type=\"text/javascript\" src=\"<a href=\"http://www.______.com/external.php?type=js\"></script>
<script language=\"\" type=\"text/javascript\">
<!--
for (var x in discussions)
{
document.writeln(\"<a href=\"http://www._______.com/showdiscussion.php?t=\"+discussion[x].discussionid+\"\">\"+discussion[x].title+\"</a> (Posted By: \"+discussion[x].poster+\")<br />\");
}
//-->
</script>";

7:24 pm on Oct 15, 2007 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



why not just break out of php?
8:14 pm on Oct 15, 2007 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Or at least use ' for your echo statement, so that you dont have to escape every " in the javascript. There did also seem to be some redundant tags in there...dont know if im just missing something, but in your first javascript block you dont need to have <a inside the src=. There did also seem to be some additional "s in there, but breaking out or at the least using ' would help to make the code easier to read and debug.

Try

echo '<script type="text/javascript"
src="http://www.______.com/external.php?type=js">
</script>
<script type="text/javascript">
<!--
for (var x in discussions)
{
document.writeln("
<a href=\"http://www._______.com/showdiscussion.php?t="
+discussion[x].discussionid+"
\">
"+discussion[x].title+"</a> (Posted By: "+discussion[x].poster+")
<br />");
}
//-->
</script>';

I think I have put the correct " and ' in but test it to make sure.