I'm doing some validation on a HTML form using min and max attributes. I also want to prevent form submission if the submit button is clicked once to prevent multiple form submissions before a page is reloaded.
Here's the inline code for disabling the button:
<input type="submit" name="name" value="REGISTER" onclick="this.disabled=true;this.form.submit();">
Here's the number input field code:
<input type="number" name="endNo" placeholder="END" min="5" max="20">
If I include the inline JS for the submit button, the min and max validation doesn't work. When removed, it seems to work just fine. Why is this happening and how can I satisfy both conditions, disable the button once clicked while still validating the min and max values for the number input field?
I'm using google chrome.
For the <meter> element, the min attribute defines the lower numeric bound of the measured range. This must be less than the minimum value ( max attribute), if specified. In both cases, if omitted, the value defaults to 1.
Disabling all form elements HTML form elements have an attribute called disabled that can be set using javascript. If you are setting it in HTML you can use disabled="disabled" but if you are using javascript you can simply set the property to true or false .
Which of the following is not a type of attribute for input tag? Explanation: Day is not defined in the pre-defined attribute list of input tag. Week attribute defines week and year when used as attribute in input tag. Month specifies month and year when it is accessed in input tag.
The submit
method on form element does what it promises, it just submits the form, doesn't do a validation. You can manually do validation with the checkValidity
method.
<input type="submit" name="name" value="REGISTER"
onclick="if(this.form.checkValidity()){this.disabled=true;this.form.submit();}">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With