Imad Abu Hayyah
Imad Abu Hayyah

Reputation: 454

Javascript param with special character

I have the following javascript function:

function Msg(strMsg){
    alert(strMsg);
}

i have the following button to call the function:

<a class="btn btn-danger" onclick="Msg('a"a');" role="button">Msg</a>

but since the strMsg passed param has a special character (") the function is not called.

The result should be: a"a

Upvotes: 1

Views: 190

Answers (1)

Ashish
Ashish

Reputation: 6939

Use Escape character :

\" Insert a double quote character in the text at this point.

<a class="btn btn-danger" onclick="Msg('a\"a');" role="button">Msg</a>

You can try something with unicode :

<a class="btn btn-danger" onclick="Msg('a&quot;a');" role="button">Msg</a>

Upvotes: 2

Related Questions