I'm a newbie to JQuery and the Validation plugin.
Short Description: I wanted all of my error messages to appear in one div at the top of the form, instead of next to each label. After a little head scratching and net searching, I came up with the following, which works, but the sourceurl: message comes up twice on the validation. I haven't a clue as to why. Any help would be appreciated. Cheers, John
Source Code:
<form name="siteauth" id="siteauth" action="savedata" type="POST">
<div class="message"></div>
<fieldset>
<label>Short Description:</label>
<br><input id="shortdescription" size="75" type="text" maxlength="50" name="shortdescription"/>
<br><label>Source URL:</label>
<br><input id ="sourceurl" size="75" type="text" maxlength="500" name="sourceurl"/>
<br><label>Callback URL:</label>
<br><input id="callbackurl" size="75" type="text" maxlength="500" name="callbackurl"/>
<br><label>Callback Content:</label>
<br><input id="in4" size="75" type="text" maxlength="100" name="callbackcontent"/>
<br>
<br><input type="submit" value="Add"/>
</fieldset>
</form>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
<script>
$(document).ready(function(){
$("#siteauth").validate({
rules: {
shortdescription: "required",
sourceurl: "required"
},
messages: {
shortdescription: "Enter a short description. ",
sourceurl: "Enter a Source URL. "
},
errorElement: "div",
wrapper: "div class=\"message\"",
errorPlacement: function (error, element){
error.appendTo($(".message"));
}
});
});