Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To accomplish what you want, you have to first create a 'dummy' option element nested in the select element and hide it with CSS. When the user changes the value, you will overwrite the dummy display value with the value of the option selected by the user.</p> <p>Afterwards, when the user goes to select a new option, the 'dummy' value will be hidden, but it will still be populated in the main select box. Here is some rough code based on your previous jsfiddle.</p> <p>Caveat: I am not sure of the compatibility of this solution.</p> <p><strong>HTML:</strong> </p> <pre><code>&lt;select id="select-el"&gt; &lt;option id="display-el" value="-1"&gt;Can't see me&lt;/option&gt; &lt;option id="id1" value="1"&gt;Option 1&lt;/option&gt; &lt;option id="id2" value="2"&gt;Option 2&lt;/option&gt; &lt;option id="id3" value="3"&gt;Option 3&lt;/option&gt; &lt;option id="id4" value="4"&gt;Option 4&lt;/option&gt; &lt;option id="id5" value="5"&gt;Option Longer&lt;/option&gt; &lt;/select&gt; </code></pre> <p><strong>CSS:</strong></p> <pre><code>#display-el { display:none; visibility: hidden; } </code></pre> <p><strong>JavaScript:</strong> </p> <pre><code>var N = 8; var selectEl = document.getElementById('select-el'); var displayEl = document.getElementById('display-el'); selectEl.onchange= function(e) { var index = selectEl.selectedIndex; var option = selectEl[index]; selectEl.selectedIndex = 0; if(option.text.length &gt; N){ displayEl.text = option.text.substr(0, N) + "..."; } else { displayEl.text = option.text } displayEl.value = option.value; console.log(displayEl.value); } </code></pre> <p>I've forked your jsFiddle here: <a href="http://jsfiddle.net/3v8yt/" rel="nofollow">http://jsfiddle.net/3v8yt/</a> so you can check it out.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload