1

I am curious if it possible to assign a tab character as value to an html dropdown list. This is my current markup:

<select id="delimiter-select" class="form-control form-control-sm csv-select">
               <option value=",">Comma (,)</option>
               <option value=";">Semi-Colon (;)</option>
               <option value="|">Pipes (|)</option>
               <option value="Tab">Tab</option>
</select>

Where the value Tab is I would like that to be a tab character that I can eventually pass to JS.

Jordan Rose
  • 300
  • 2
  • 13
  • 1
    Possible duplicate of [How to get a tab character?](https://stackoverflow.com/questions/9660987/how-to-get-a-tab-character) – Cory Kleiser Jun 05 '18 at 12:34

2 Answers2

3

There is a HTML entity for the Tab character, &Tab; or &#9;, use that:

document.getElementById("delimiter-select").onchange = function (e) {console.log(` Separator is ${e.target.value} separating`)}
<select id="delimiter-select" class="form-control form-control-sm csv-select">
  <option value=",">Comma (,)</option>
  <option value=";">Semi-Colon (;)</option>
  <option value="|">Pipes (|)</option>
  <option value="&Tab;">Tab</option>
</select>
Luca Kiebel
  • 9,790
  • 7
  • 29
  • 44
  • It is confusing that when I look at the dom structure and only see a white space character but it sends a tab character to javascript. Any idea why it behaves this way? – Jordan Rose Jun 05 '18 at 12:44
  • @JordanRose because tab is just white space. – Cory Kleiser Jun 05 '18 at 12:46
  • All HTML entities behave that way, they are just representations of the actual character, a Tab, as Cory wrote is just white space, you can't see it when it's rendered – Luca Kiebel Jun 05 '18 at 12:47
0

Use &#9; as the tabulation HTML entity

console.log($('#input').val() + 'Test');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="input" value="&#9;">
Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112