April 9th, 2013, 01:37 PM
OnClick and other events
Must they always have double quotes, such as
onClick="function('value');" or can they have single quotes such as
April 9th, 2013, 02:17 PM
You can put double quotes in single quotes, you can put single quotes in double quotes, or you can escape the inner quotes (with & quot; or &34; ). Depending on the HTML flavor, you can even leave out the attribute quotes completely. But you cannot put single quotes in single quotes or double quotes in double quotes. Like I said, this applies to every mainstream language, so it shouldn't really surprise you.
April 10th, 2013, 05:59 AM
So would I get away with using something like this?
April 10th, 2013, 06:45 AM
No, because now you've killed the attribute quotes.
An HTML attribute looks like this:
In case the attribute content itself contains quotes, these quotes either have to be different from the attribute delimiters, or you need to escape the quotes of the attribute content:
If the HTML is in a PHP string, then again the quotes in the string have to be different from the string delimiters, or you need to escape the quotes in the string content:
onclick="alert(" ;abc" ;)"
echo '<strong onclick="alert(" ;abc" ;)">Click!</strong>';
or any other combination that fulfills the requirements above.
echo '<strong onclick="alert(\'abc\')">Click!</strong>';
Comments on this post
April 10th, 2013, 08:23 AM
Well, the particular event I am using is
I know of the alert event or warning, but don't how to use it with my php
April 10th, 2013, 08:44 AM
Didn't I explain that above? If you want something to copy and paste, pick one of the last two code snippets.
Originally Posted by cssbonding
April 10th, 2013, 09:54 AM
The premise is simple, cssbonding. In layman's terms: A machine reads in sequence. Take the following code:-
Using the forums built-in highlighting, do you see how the machine is going to interpret that code? It takes the first double quotation mark as the opening point of your parenthesis and then it takes the second as the closing point, then repeats when it finds a second set of quotation marks. It does not understand your intent, only syntax and logical order.
<element onclick="someFunction("a string");">
By using the following examples of single and double quotation marks, you are differentiating between your parenthesis, allowing you to nest them inside one another.
<element onclick="someFunction('a string');">
<element onclick='someFunction("a string");'>
Comments on this post