Escaping Apostrophes in Javascript Generated From PHP

zmtun84

New Member
I am trying to have a textfield with an initial value, where if you click on it, the text disappears, and if you click out before anything has been entered the initial value returns much like the search box on Yahoo answers and many other sites. \[code\]echo "<input type=\"text\" onblur=\"if (this.value =http://stackoverflow.com/questions/3647944/='') {this.valuehttp://stackoverflow.com/questions/3647944/= 'http://stackoverflow.com/questions/3647944/$cleaned';}\" onfocus=\"if (this.value =http://stackoverflow.com/questions/3647944/='$cleaned') {this.valuehttp://stackoverflow.com/questions/3647944/= '';}\" value=http://stackoverflow.com/"$cleaned\" />\n";\[/code\]I have a php variable \[code\]$cleaned\[/code\] as my initial value. This code works, except for the case when the variable cleaned has an apostrophe in it, like \[code\]$cleaned = "FRIEND'S"\[/code\]. Then the code would read \[code\]this.valuehttp://stackoverflow.com/questions/3647944/= 'FRIEND'S'\[/code\] and the apostrophe in \[code\]FRIEND'S\[/code\] ends the string early. I have tried using html entities, escaping the apostrophe, and using escaped quotes and cannot get this case to work. The only solution I have so far is to replace apostrophes with characters that look like apostrophes. Does anyone know how to handle this case?
 
Back
Top