Skip to content

Instantly share code, notes, and snippets.

@jonathansampson
Created August 4, 2014 15:48
Show Gist options
  • Select an option

  • Save jonathansampson/c9071cc90e0014f4859f to your computer and use it in GitHub Desktop.

Select an option

Save jonathansampson/c9071cc90e0014f4859f to your computer and use it in GitHub Desktop.

Revisions

  1. jonathansampson renamed this gist Aug 4, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. jonathansampson created this gist Aug 4, 2014.
    23 changes: 23 additions & 0 deletions valueAsNumber
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    (function () {

    /* Internet Explorer 11 may have trouble retrieving the number type
    of an input value. This short script performs a quick test, and repairs
    the functionality if necessary. Load before attempting to use the
    `valueAsNumber` property on input elements. */

    "use strict";

    var a = document.createElement( "input" );

    a.setAttribute( "type", "number" );
    a.setAttribute( "value", 2319 );

    if ( "valueAsNumber" in a && a.value != a.valueAsNumber ) {
    if ( "defineProperty" in Object && "getPrototypeOf" in Object ) {
    Object.defineProperty( Object.getPrototypeOf( a ), "valueAsNumber", {
    get: function () { return parseInt( this.value, 10 ); }
    });
    }
    }

    }());