Jordan Rose
Jordan Rose

Reputation: 300

Possible to assign tab value to html form element?

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.

Upvotes: 1

Views: 300

Answers (2)

Luca Kiebel
Luca Kiebel

Reputation: 10096

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>

Upvotes: 3

Suren Srapyan
Suren Srapyan

Reputation: 68685

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;">

Upvotes: 0

Related Questions