View Full Version : Avoid quotes in onclick?

11-30-2007, 08:15 PM
Need to avoid the quotes around the onclick action in my html code to to php. is this possible?

Current call

<input type="button" value="Steg 1" onclick="show('QA')"/>

Want it to be

<input type="button" value="Steg 1" onclick="show(QA)"/>

My javascript

function show(id) {

var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
e.style.display = 'block';


11-30-2007, 08:16 PM
If and only if a variable QA is defined somewere in let's say a script tag defined before the element in question. Basically, that would create more trouble than it's worth. Try using \" instead of '

11-30-2007, 08:19 PM
You can do:
<input type="button" value="Steg 1" onclick="show(&quot;QA&quot;)">but this is very ugly. The fact that you need to do this is generally indicative of poor coding practices in the PHP. Break out of PHP parsing mode to output HTML, or even better, use a dedicated template system like Smarty (http://smarty.php.net/).

Also read http://www.webdevout.net/articles/beware-of-xhtml and http://www.hixie.ch/advocacy/xhtml for reasons not to use XHTML at the present.