<div id="content" style="padding: 10px;">
<form id="frmTest" method="get">
Lots of other content here<br />
Lots of other content here<br />
Lots of other content here<br />
Lots of other content here<br />
Lots of other content here<br />
Lots of other content here<br />
<input id="txtEmail" name="txtEmail" type="text" class="required email"/>
<br />
<input id="txtName" name="txtName" type="text" class="required" minlength="2"/>
<br />
Other content
<br />
<button id="btnValidate" type="button">Test validation</button>
</form>
</div>
label.invalid
{
color: Red;
font-style: italic;
padding: 1px;
margin: 0px 0px 0px 5px;
}
$(document).ready(function ()
{
// Bind validation rules
$("#frmTest").validate({
errorClass: "invalid"
});
// Bind click handler:
$("#btnValidate").click(function ()
{
if ($("#frmTest").valid())
alert("Valid");
});
});
If you need extra help with designing your app with Javascript, you can’t go wrong with this fantastic book from Douglas Crockford:
JavaScript: The Good Parts