Karthik
Karthik

Reputation: 377

remove the character / from a javascript string

Overview: I am passing a string to my javascript function, here the code:

HTML:

<span onclick='fSaveComment(/@item.model.szUserName/)'></span>

Javascript:

function fSaveComment(szUserName) {  

   // If I assign the following line, it strips the first and last characters,
   // if I use szUserName from the function param list, it does not work!!!
   // 
   //szUserName = '/aabbcc/'; 

   myString = szUserName.substr(1, szUserName.length-2);                             
}

What am I doing wrong?

Upvotes: 0

Views: 266

Answers (1)

Tim Abell
Tim Abell

Reputation: 11901

You need to correctly quote the username passed to the fSaveComment function

<span onclick='fSaveComment("@item.model.szUserName")'></span>

Upvotes: 1

Related Questions