Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

echo back javascript problem

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

Full Member

10+ Year Member

joined:Jan 27, 2005
posts: 229
votes: 0

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 />\");

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


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

joined:July 24, 2001
votes: 0

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 12, 2007
votes: 0

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.


echo '<script type="text/javascript"
<script type="text/javascript">
for (var x in discussions)
<a href=\"http://www._______.com/showdiscussion.php?t="
"+discussion[x].title+"</a> (Posted By: "+discussion[x].poster+")
<br />");

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