0

I'm having a problem taking input from a textbox and adding it to a sting, it involves the '\' char. Since a normal string will see this as an escape it will screw up a string that I then pass to another function. I'm new to javascript and yui so I'm just wondering if there is a built in way to escape a string value I get from the textbox, so it will take a '\' and make it a "\" and so on.

My code looks a little like this

var requestStr = "\" Request\"";
requestStr = requestStr + "\"" + document.getElementById("textbox").value + "\",";

Edit: Fixed code to properly show my example

jacoba
  • 57
  • 6

1 Answers1

0

try this

var s=document.getElementById("textbox").value
if(var x=s.IndexOf('\\')){
s[x]='\\';
requestStr =requestStr +s ;
}
else
{
   requestStr =requestStr+ s;
}

output will be: "request" "value\" or "request" "value"

Arpit
  • 12,767
  • 3
  • 27
  • 40