How not to validate HTML5 text box with required attribute

﹥>﹥吖頭↗ 提交于 2019-11-29 01:15:32

Try this;

<button type="button" formnovalidate>Cancel</button>

I changed your code: What you want is that your form should not be validated on click of cancel, so that's why i added the formnovalidate to the button cancel.

<form>
    <input type="number" min="1" max="100" required />
    <input type="submit">Add</input>
    <input type="submit" formnovalidate>Cancel</input>
</form>

Try to add formnovalidate attribute to your cancel button

<button type="button" formnovalidate>Cancel</button>
proditor

You could use the formnovalidate-option on the cancel-button, like this:

<input name="cancel" type="submit" value="Cancel" formnovalidate/>

See Symfony2 form validation with html5 and CANCEL button

Bhavin Mistry

If you have the input button as runat=server then you must have the property causesvalidation="false" or else if you are simply using html input type button for cancel use javascript to redirect to your page on click of cancel.

For eg. 1)

<input type="button" id="btnCancel" class="button blue" value="Cancel" **causesvalidation="false"** onserverclick="btnCancel_Click" runat="server" />

2)

<input type="button" id="btnCancel" class="button blue" value="Cancel" **onclick="GoTo();"**/>

<script type="text/javascript">
function GoTo() {
            window.location.href = '../default.aspx';
        }
</script>

Try this code at asp.net 5enter link description here button control

<form>
<input type="number" min="1" max="100" required />
<button type="button">Add</button>
<button type="button" formnovalidate="formnovalidate">Cancel</button>

Aldo Flores Reyes @alduar .net news

try this one.it works fine.It will work on submit button

<asp:TextBox runat="server" ID="inputusername" required />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!