Doubt about HTML input attributes

Asked

Viewed 205 times

1

Hello, everyone. I’m doing a Tabuada using HTML and PHP. The user enters a number through a form and the table is displayed. I wonder if I can put some attribute in <input type="number>"so that only positive numbers are displayed in the user selection field. Today my code is like this:

<!--CAMPO PARA DIGITAR O NÚMERO-->
    <label>Número:</label>
    <input type="number" name="numero">

From now on, thank you!

3 answers

3


The properties min and max of an input define the minimum and maximum values respectively. <input type="number" min="0" name="numero">

  • Thank you, Thiago. It helped a lot!

2

The input being the type number, you can define the minimum and maximum values through the attributes min and max, respectively.

<input type="number" name="numero" min="0" max="9">

If you want any positive value, simply remove the attribute max.

  • Thank you, Anderson. You’ve been very helpful!

2

As user Thiago has already answered, you can use the attributes min and max HTML5.

The only problem is that they will not work in older browsers. In these cases it is always interesting to use a polyfill to ensure that older browsers also have the functionality.

A cool plugin for jQuery that has a compatibility is the Stepper.

  • Thanks, @jHertel. I’ll keep an eye on that!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.