Welcome to WebmasterWorld Guest from 54.167.58.159

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Problem with PHP and JS

     

andrewsmd

9:02 pm on Mar 17, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I am trying to run a javascript function with PHP. However, I get a JS error saying unterminated string literal with this php code. Echo("<a href = # onclick=checkName('{$rcd}', '{$title}')> Del </a>");
The only problem I can see is that in the html it looks like this checkName('91', 'AD1 Moore'); The script stops at the blank white space. Any ideas why a white space is causing me issues? I should note that checkName calls some AJAX stuff.

gsmith

11:30 pm on Mar 17, 2010 (gmt 0)

10+ Year Member



Why is there a hash mark after href = ?

Also, if this is supposed to by XHTML, then the attribute value has to be enclosed in double quotes.

rocknbil

11:55 pm on Mar 17, 2010 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Right, needs quotes.

echo "<a href=\"#\" onclick=\"checkName('$rcd', '$title')\"> Del </a>";

Readie

12:03 am on Mar 18, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Just a note, I seem to recall reading echo is not treated like a function and so will not work with brackets when more than one parameter is passed to it. Whether that means concatonated variables, or variables split with a delimiter of some sorts I don't know.

andrewsmd

12:16 am on Mar 18, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



That's what I was missing. The \ was just a typo. Thanks guys, it's been a while since I've done anything with PHP. I guess I got too used to .net and it handling all of that "AJAX stuff" for me! I've used echo with multiple variables a lot before. Could this be a version issue? I've never had a problem with it.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month