This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 25663 - Make select() work silently on all form controls to which it currently doesn't apply
Summary: Make select() work silently on all form controls to which it currently doesn'...
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 enhancement
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
Depends on:
Reported: 2014-05-12 18:34 UTC by Ian 'Hixie' Hickson
Modified: 2017-03-10 05:45 UTC (History)
18 users (show)

See Also:


Description Ian 'Hixie' Hickson 2014-05-12 18:34:18 UTC
It's been suggested that even on form controls where you can't normally interact programmatically with the selection (e.g. type=number), it would be useful to have a way to tell the browser to select everything so that when the user starts entering a value, it deletes the previous value.

This could be done in a way that is separate from the rest of the selection API, e.g. no firing 'select' events, no selectionStart API, etc.

Any vendors interested in supporting that?

ack Sampo Niskanen from bug 24796.
Comment 1 Kent Tamura 2014-05-13 10:44:46 UTC
+1. This sounds useful, and implementation cost is low.
Comment 2 Jonathan Watt 2014-05-15 21:57:47 UTC
Comment 3 Ian 'Hixie' Hickson 2014-07-30 23:21:09 UTC
Ok, I'll make select() apply to the following fields:

  Text, Search (already applies)
  URL, Telephone (already applies)
  Password (already applies)
  Date and Time, Date, Month, Week, Time Local Date and Time
  File Upload

For browsers where it makes no sense (e.g. if "Colour" is a colour well, or if "Week" is only a calendar widget) then it'll just do nothing (not throw, like now).
Comment 4 stephen.cunliffe 2014-07-31 20:41:32 UTC
Awesome. I'm very glad this got reverted. It isn't quite the full suite of selection properties/methods we need back but it is a start.  Thanks for reconsidering.
Comment 5 contributor 2014-09-17 23:09:05 UTC
Checked in as WHATWG revision r8785.
Check-in comment: Add the select() method to input types that might have text fields but where the script-exposed value is unlikely to exactly match the user-exposed value, so that the selection can be switched on, even if it can't be carefully managed.
Comment 6 Habib Virji 2014-09-25 08:53:47 UTC
Contrary to below changes, select() API seem to not throw error in all browsers.

Found following behavior:
1. Chrome, Firefox. IE and Opera do not throw error for select() on all input type (including non text fields, radio, checkbox, button). It does throw error for selection API. 
--> data:text/html,<input type=radio value='1' id=radio><script> try { document.getElementById('radio').select();} catch(e) {console.log(e); }</script>

2. On all browsers select() function, selects all text in input type email. 
--> data:text/html,<input type=email value='' id=email> <script> try { document.getElementById('email').select();} catch(e) { console.log(e);}</script>
3. In Opera and Firefox, selection API() works for input type email. 
--> data:text/html,<input type=email value='' id=email> <script> try { document.getElementById('email').select(); console.log(document.getElementById('email').selectionEnd);} catch(e) { console.log(e);}</script>

4. In Chrome and Opera select(), select all number in input type number. 
--> data:text/html,<input type=number value=2000 id=number> <script> try { document.getElementById('number').select();} catch(e) { console.log(e);}</script>
5. In Opera, selection API works for input type number. 
--> data:text/html,<input type=number value=2000 id=number> <script> try { document.getElementById('number').select(); console.log(document.getElementById('number').selectionEnd);} catch(e) { console.log(e);}</script>

6. Firefox allows using selection API on input type date. While Opera and Chrome throws exception.
--> data:text/html,<input type=date value="2000-10-10" id=date> <script> try { document.getElementById('date').select(); console.log(document.getElementById('date').selectionEnd);} catch(e) { console.log(e);}</script>

7. Only Chrome, selects radio, checkbox, file and color element. None of the other browsers does.