input type number min max

by Dwi Adi Laksono

HTML

<script src="http://tjvantoll.com/images/posts/2012-07-15/dependencies.js"></script>
<link rel="stylesheet" href="http://tjvantoll.com/images/posts/2012-07-15/dependencies.css">
<h3>Currency - USD</h3>
$ <input type="number" min="1" step="1000" max="2500" value="25.67" />

CSS

body { padding: 5px; }
h3:first-child { margin-top: 0; }
h3 { margin-top: 10px; margin-bottom: 2px; }

JavaScript

$('input[type="number"]').change(function() {
    var min = Globalize.parseFloat($(this).attr("min"));
    var max = Globalize.parseFloat($(this).attr("max"));
    var value = Globalize.parseFloat($(this).val());
    if(value < min) { value = min; }        
    if(value > max) { value = max; }
    $(this).val(value);
    //value = Globalize.format(value,"c");
    console.log(value);
    
});