I solved it by doing this in the PHP code:
Code:
function cl_html_entity_encode($str){
return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str);
}
And changing one of the last lines to:
Code:
$sendstring=cl_html_entity_encode(substr($sendstring,0,strlen($sendstring)-1));
Then added this function to my JavaScript:
Code:
function html_entity_decode(str) {
var ta=document.createElement("textarea");
ta.innerHTML=str.replace(/</g,"<").replace(/>/g,">");
return ta.value;
}
Then this further down:
Code:
tmpstr=html_entity_decode(xmlHttp.responseText)
eval("var d="+tmpstr);
So I basically encode them as HTML entities in PHP, then decode them in Javascript before I put the values into my dropdown box. And it works nicely.
Just wanted to share if anyone else had the same or similar problems.
Bookmarks