Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html5 required validator not working with input type=button

Here is my html code

<form id="form1" runat="server">
<input id="q" required />
<input id="btn" type="submit" value="Search">
</form>

I have used html5 required field validators, it works but with a post back. so modified the code as follows to avoid postback

<form id="form1" runat="server">
<input id="q" required />
<input id="btn" type="button" value="Search">
</form>

But the required validator doesn't work

like image 997
iJade Avatar asked Jun 18 '13 07:06

iJade


1 Answers

That's because the required validator is only called on submit, and the type=button is not a submit. Try this (http://jsfiddle.net/upgradellc/vrTLw/):

<form id="form1" runat="server">
    <input id="q" required />
    <input id="btn" type="submit" value="Search">
</form>
like image 57
Max Avatar answered Oct 04 '22 06:10

Max