acctman
acctman

Reputation: 4349

Setting minimum number value input in input textbox

I'm trying to make the minimum allowed input amount to be 1.00 and not to allow 0.99 or anything less than 1.00

<input type="text" onkeyup="switchSlider(this.value, 1)" value="25.00" class="master-amount" name="master-amount" id="master-amount">

Upvotes: 1

Views: 2443

Answers (2)

MartinWebb
MartinWebb

Reputation: 2008

Update:

You can test the value on keyup as per code below and force 1 as the min value.

<input type="number" onkeyup="switchSlider(this)" value="25.00" class="master-amount" name="master-amount" id="master-amount">


switchSlider = function (e){
   if (!e.value || e.value < 1) e.value=1;
}

http://jsfiddle.net/2dq06qpc/

You can do this right in your markup using the min max and step attributes, note you need to use type="number"

<input type="number" min="0" max="100" step="5">

In your code:

<input min="1" type="number" onkeyup="switchSlider(this.value, 1)" value="25.00" class="master-amount" name="master-amount" id="master-amount">

Upvotes: 0

Ashima
Ashima

Reputation: 4824

User HTML min Attribute

<input type="number" min="1.00" onkeyup="switchSlider(this.value, 1)" value="25.00" class="master-amount" name="master-amount" id="master-amount">

Here is an example for you

http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_max_min

Upvotes: 2

Related Questions