0

I have some input

<input id = 'some_id' type='text'/>

I want to set value with backslash, for example:

$('#some_id').val('someval \') 

and I'm getting error:

Uncaught SyntaxError: Invalid or unexpected token

How can I show string value with backslash in input ?

godot
  • 3,422
  • 6
  • 25
  • 42

1 Answers1

1

Escape the \ character like this: $('#some_id').val('someval \\')

$('#some_id').val('someval \\') 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id = 'some_id' type='text'/>
lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
  • how can I do it dynamically ? when I'm getting some string variable and I don't know how it looks like ? – godot Jul 16 '18 at 17:55
  • @godot did you ask a separate question for this? or did you vote to reopen the original one? I'm asking because I think it would be good to do that in order to see it in context with this new requirement. Let me know... – lealceldeiro Jul 16 '18 at 17:59
  • you think that I should ask new question about it? – godot Jul 16 '18 at 17:59
  • @godot I think so, because it would be good to see it as you describe it now, besides it would be too difficult to answer in a comment and if I update the answer it won't help future readers because the original post states a different thing (it doesn't talk about the dynamic part). Drop a link here with the new question. – lealceldeiro Jul 16 '18 at 18:03
  • okay, I accepted your answer. – godot Jul 16 '18 at 18:04