CodeIgniter Forums
javascript confirmation with html character code - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: javascript confirmation with html character code (/showthread.php?tid=19048)



javascript confirmation with html character code - El Forum - 05-26-2009

[eluser]Jagar[/eluser]
I know this has nothing to do with CI, but I hope somebody knows the answer.

Admins have a list of all the items they have added, and trying to make everything as safe as possible, the only think that is not working is the javascript confirmation, such as the following:

Code:
return confirm('Are you sure you wish to delete Don't be sad?');"

That is attached to a link when the user clicks on it, they will get that confirmation, but in this case that character ' is the single quote, so it shouldn't be a problem with javascript since it's safe. But it is not, when items such as that with single quote, gets clicked, the user does not get a confirmation, but it gets deleted right away,

Is there any way around this?

Thanks


javascript confirmation with html character code - El Forum - 05-26-2009

[eluser]drewbee[/eluser]
Even though it is an entity, javascript still interprets it as a single quote. You still need to make sure you are escaping the entity version of it with a backslash.

Code:
var string = 'ampersand & woot & and &<';
    string = string.replace(/&/gi,'\&');
    alert(string);



javascript confirmation with html character code - El Forum - 05-26-2009

[eluser]Jagar[/eluser]
Thanks for the reply, that will solve the problem.