Click here to Skip to main content
15,747,356 members
Please Sign up or sign in to vote.
4.20/5 (2 votes)
See more:
I am having a problem where the "\\" and "\" are getting removed from my file path

<span  önClick=\"playRec('" + path + "');\">Play</span>

function playRec(val) {

the val is showing an incorrect filepath.
CBadger 24-Apr-14 7:32am    
What does path show?
So in debug what is the actual value op path and what gets passed into the query then to what does it change to?
Linkz_G 24-Apr-14 8:06am    
this is how the path shows:

but in my function playrec the val is:
Shah Parth P 24-Apr-14 7:45am    
you can fix the path of a file by using static string.
and keep the file name dynamic only.
Take file name form the user if possible.
or specify how you want to call it???

Try using a regex to keep escape characters

var val = $(this).attr('val').replace(/[!"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~]/g, "\\\\$&")

Although in your case you can also try and use the filter[§] settings
with all elements selection
var value = this.value;
$select.find('option').filter(function() {
  return this.value == value;
Share this answer
this fixed the issue:

path = path.replace(/[\\]/g, "\\\\");
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900