C Sharper
C Sharper

Reputation: 8626

Replacing double quotes while sending parameter to javascript function

This is JSFiddle :

http://jsfiddle.net/5kdek3vn/

I have button as follows:

<button class="buttoncss" title="Modify This Artifact File" onclick="setFileDescriptionForUpdate('!@#$%^&amp;*()_+-=~`{}|[]\:" ;'&lt;&gt;?,.="" ','state.dat','167','1','c:\\pp_artifactsuploadedfiles\evalid_318\state.dat');">Modify</button>

in this on click i am calling setFileDescriptionForUpdate function whose first parameter is string and is as follows:

!@#$%^&*()_+-=~`{}|[]\:";'<>?,./

when " is involved in string it creates problem.

What changes i can make to avoid this??

Please help me.

Upvotes: 0

Views: 643

Answers (2)

Jankya
Jankya

Reputation: 958

Use below Code :-

var user = "Hi \" User";
var test = user.replace("\"", "");
document.body.innerHTML = test;

Upvotes: 1

Liam
Liam

Reputation: 2837

HTML escaping is required if going inline.

If you have to use inline javascript in html then you have to escape it

& becomes &amp;
< becomes &lt;
> becomes &gt;

In attribute values you must also escape the quote character [spec]:

" becomes &quot;
' becomes &#39;

Upvotes: 2

Related Questions