I want to replace &
to &
using javascript. Here is the sample code of mine.EmployeeCode
could contain &. The EmployeeCode is selected from Datagrid and its showed in "txtEmployeeCode" textbox. But if the EmployeeCode contains any &
then it shows &
into the textbox. How could &
be removed from EmployeeCode? can anyone help...
function closewin(EmployeeCode) {
opener.document.Form1.txtEmployeeCode.value = EmployeeCode;
this.close();
}
With this:
function unEntity(str){
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
}
function closewin(EmployeeCode) {
opener.document.Form1.txtEmployeeCode.value = unEntity(EmployeeCode);
this.close();
}
OPTIONAL If you are using jQuery, this will decode any html entity (not only &
<
and >
):
function unEntity(str){
return $("<textarea></textarea>").html(str).text();
}
Cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With