justinh Posted December 8, 2008 Share Posted December 8, 2008 Is there anything special you have to do to echo a semicolon? I have this code echo "<div id=\"category\" onclick=\"location.href=default.php?catid".$cats['cat_id'].";\">; And for some reason it isn't linking to anything. It does work in plain html. But, once i bring it into PHP it doesn't seem to work. You can see what I'm talking about here: http://www.wmptest.com/clintormscart/default.php this should take you to that category's page Quote Link to comment https://forums.phpfreaks.com/topic/136097-semicolon/ Share on other sites More sharing options...
rhodesa Posted December 8, 2008 Share Posted December 8, 2008 should be: echo "<div id=\"category\" onclick=\"window.location.href='default.php?catid=".$cats['cat_id']."';\">; Quote Link to comment https://forums.phpfreaks.com/topic/136097-semicolon/#findComment-709638 Share on other sites More sharing options...
wildteen88 Posted December 8, 2008 Share Posted December 8, 2008 EDIT: Nevermind beaten to it Its a JavaScript error. It should be: echo "<div id=\"category\" onclick=\"location.href='default.php?catid".$cats['cat_id']."';\">; Alternatively your should remove the onClick even entirely and wrap the contents of the div within an anchor tag, eg echo "<div id=\"category\"><a href=\"default.php?catid".$cats['cat_id'].|"\">DIV CONTENT HERE</a></div>"; Quote Link to comment https://forums.phpfreaks.com/topic/136097-semicolon/#findComment-709641 Share on other sites More sharing options...
justinh Posted December 8, 2008 Author Share Posted December 8, 2008 hmmm that didnt work either.. heres the result: http://www.wmptest.com/clintormscart/default.php Quote Link to comment https://forums.phpfreaks.com/topic/136097-semicolon/#findComment-709642 Share on other sites More sharing options...
gevans Posted December 8, 2008 Share Posted December 8, 2008 You need to 'escape it' A backslash can be used in php to escape characters you want to use that are used within php itself; echo "<div id=\"category\" onclick=\"location.href='default.php?catid".$cats['cat_id']."'\;\">"; You also missed the last double quote to close the variable string Quote Link to comment https://forums.phpfreaks.com/topic/136097-semicolon/#findComment-709644 Share on other sites More sharing options...
wildteen88 Posted December 8, 2008 Share Posted December 8, 2008 The links are working fine for me. However it loads the same content no mater what category you choose. Quote Link to comment https://forums.phpfreaks.com/topic/136097-semicolon/#findComment-709645 Share on other sites More sharing options...
justinh Posted December 8, 2008 Author Share Posted December 8, 2008 okay everything works great.. ty guys.. =) Quote Link to comment https://forums.phpfreaks.com/topic/136097-semicolon/#findComment-709648 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 hmmm that didnt work either.. heres the result: http://www.wmptest.com/clintormscart/default.php Honestly, for only 1 javascript statement, you do not need the semicolon, but as pointed out above, it was not the semicolon causing issues. It was the whole echo and not properly escaping certain elements: echo "<div id=\"category\" onclick=\"location.href='default.php?catid".$cats['cat_id']."'\">Content Here</div>"; Should work. But as stated, the semicolon was not causing the issue, just a non-escaped echo statement. Quote Link to comment https://forums.phpfreaks.com/topic/136097-semicolon/#findComment-709651 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.