user3523642
user3523642

Reputation: 23

Failed to execute 'setSelectionRange' on 'HTMLInputElement'

I have the following error an simle "number" input field in Chrome (ver. 33 =>) and other webkit browsers

<input type="number" name="number">

Failed to execute 'setSelectionRange' on 'HTMLInputElement': The input element's type ('number') does not support selection.

I tested in FF & IE (10=>) and working well

I found the following issue in chromium project: https://code.google.com/p/chromium/issues/detail?id=346270

any idea?

thank you!

Upvotes: 2

Views: 6839

Answers (1)

wpdaniel
wpdaniel

Reputation: 762

Yes, this is an webkit bug, try this solution:

Jsfiddle demo

Code:

    <div class="container">
        <form role="form">
          <div class="form-group">
            <label for="tel">tel</label>
              <input type="tel" class="form-control" id="tel" placeholder="tel"/>
          </div>
        </form>
    </div>

    <script>
    $("#tel").mask("(99) 999-9999");

    $("#tel").on("blur", function() {
        var last = $(this).val().substr( $(this).val().indexOf("-") + 1 );

        if( last.length == 3 ) {
            var move = $(this).val().substr( $(this).val().indexOf("-") - 1, 1 );
            var lastfour = move + last;
            var first = $(this).val().substr( 0, 9 );

            $(this).val( first + '-' + lastfour );
        }
    });
    </script>

Upvotes: 2

Related Questions