i've searched web try learn i'm missing, can't seem it. i'm using asp.net 4.0 (webforms obviously), master pages, , jquery validation. can tell me i'm messing up?
in case, won't know fields require validation, i'd use default method of having fields class="required email", etc.
the fields , submit button regular html, not asp.net controls (long story). when page renders, form "form1", not aspnetform i've seen other people reference. when submit button clicked, doesn't hit of javascript. posts back. doesn't popup alert box.
what not referencing correctly?
here simple javascript:
$(document).ready(function () { alert('in js'); document.getelementbyid('form1').validate({ alert('in val'); });
page content:
<fieldset> <legend>a simple comment form submit validation , default messages</legend> <p> <label for="cname">name</label> <em>*</em><input id="cname" name="name" size="25" class="required" minlength="2" /> </p> <p> <label for="cemail">e-mail</label> <em>*</em><input id="cemail" name="email" size="25" class="required email" /> </p> <p> <label for="curl">url</label> <em> </em><input id="curl" name="url" size="25" class="url" value="" /> </p> <p> <label for="ccomment">your comment</label> <em>*</em><textarea id="ccomment" name="comment" cols="22" class="required"></textarea> </p> <p> <input name="btnsubmit" id="btnsubmit" class="submit" type="submit" value="submit"/> </p> </fieldset>
asp.net going place 1 form on page, use $("form") find without knowing id. also, validate options won't take alert have it, can move correct handlers i've done below. hope helps...
$(function () { $("form").validate({ submithandler: function () { alert("submiting..."); return false; }, invalidhandler: function () { alert("invalid form"); return false; } }); });
Comments
Post a Comment