1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Make form allow minimum number 10 or higher to be inputted

Discussion in 'Programming' started by Scorpion Ghost, Apr 10, 2017.

  1. Scorpion Ghost

    Scorpion Ghost Senior Member

    Joined:
    Mar 22, 2013
    Messages:
    1,073
    Likes Received:
    250
    Occupation:
    Internet!
    Location:
    On the Interwebz
    Home Page:
    I have a form on my site, and I want to make the minimum number that's allowed to be inputted be 10 or higher.

    Here's the code for that form:

    PHP:
    <input type="number" id="amount" onchange="updateInput(this.value)" class="form-control" value="10" placeholder="1.00" autocomplete="off" required>
    Can anyone help me get this done?

    Thank you
     
  2. br_amar

    br_amar Newbie

    Joined:
    Jun 20, 2013
    Messages:
    3
    Likes Received:
    0
    I suppose adding "min" attribute with value set to 10 should do the trick:

    PHP:
    <input type="number" id="amount" onchange="updateInput(this.value)" class="form-control"  min="10" value="10" placeholder="1.00" autocomplete="off" required>
     
  3. Captain America

    Captain America Newbie

    Joined:
    Apr 8, 2017
    Messages:
    24
    Likes Received:
    8
    Gender:
    Male
    br amar is right, but I'd like add that the min attribute is new in HTML5. So if you want browser cross-compatibility add in a JavaScript function to do a secondary check.

    For Example: (i dont have nuff posts yet so copy and paste the following into your URL box.
    jsfiddle.net/2dq06qpc/

    Note: replace the 1 with 10 if you want the min number to be 10.