Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I added the code below to select whole text when user click on input box:

<input type="number" onclick="this.setSelectionRange(0, this.value.length)" name="quantity" /> 

But I receive the error below:

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

like image 363
Nick Mehrdad Babaki Avatar asked Oct 29 '15 04:10

Nick Mehrdad Babaki


1 Answers

Use input type="tel" instead.

For your example:

<input type="tel" onclick="this.setSelectionRange(0, this.value.length)" name="quantity" /> 

That will do the trick and avoid the error message.

And on mobile phones, it shows up the desired number pad.

like image 106
Avatar Avatar answered Sep 22 '22 00:09

Avatar