Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/136097-semicolon/
Share on other sites

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>";

Link to comment
https://forums.phpfreaks.com/topic/136097-semicolon/#findComment-709641
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/136097-semicolon/#findComment-709644
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/136097-semicolon/#findComment-709651
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.