I am having problems echoing a string which contains a HTML select element with javascript inside
Input at Server
echo '<select name="services" onchange="document.getElementById("services").style.display = this.options.selectedIndex ? "block" : "none";" >';
Output in Browser
<select "none";"="" :="" "block"="" ?="" services").style.display="this.options.selectedIndex" onchange="document.getElementById(" name="services"></select>
I have tried escaping the strings using \ character but nothing seems to work.
echo '<select name="services" onchange="document.getElementById(\"services\").style.display = this.options.selectedIndex ? \"block\" : \"none\";" >';
Outputs
<select \"none\";"="" :="" \"block\"="" ?="" services\").style.display="this.options.selectedIndex" onchange="document.getElementById(\" name="services"></select>
Any tricks or hacks to work around this problem?
Thanks
"characters in the values, which is a general HTML attribute rule.