Algi
Algi

Reputation: 195

Display Backslash in html text box

I am not able to display text with backslashes in my textbox. \t places a tab(4 spaces) in the text box like

C: able instead of C:\table

<input type="text" id="input" />
<div>
    <input style="margin-top: 20px;" type="button" id='btn' value="Set new value" />
</div>

$('#btn').on('click', function () {
     var testval = 'C:\table';
    $('#input').val(testval);
});

Is there a way to escape this backslah and display the path completely?

Upvotes: 2

Views: 6886

Answers (3)

vorillaz
vorillaz

Reputation: 6266

Escape the backslash as : var testval = 'C:\\table'; or try using

var testval = 'C:\table';
JSON.stringify(testval);

Upvotes: 0

Jonathan Zerox
Jonathan Zerox

Reputation: 140

Put two backslaces: instead of 'C:\table' -> use 'C:\table'

this works for all languages( that's how you escape special characters )

Upvotes: 1

interested
interested

Reputation: 324

You have to escape the back slash, otherwise it's interpreted as an tab:

"C:\\table"

Upvotes: 7

Related Questions