homepage Welcome to WebmasterWorld Guest from 54.237.98.229
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Problem with PHP and JS
andrewsmd

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4099883 posted 9:02 pm on Mar 17, 2010 (gmt 0)

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

10+ Year Member



 
Msg#: 4099883 posted 11:30 pm on Mar 17, 2010 (gmt 0)

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

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



 
Msg#: 4099883 posted 11:55 pm on Mar 17, 2010 (gmt 0)

Right, needs quotes.

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

Readie

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4099883 posted 12:03 am on Mar 18, 2010 (gmt 0)

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

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4099883 posted 12:16 am on Mar 18, 2010 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved