jQuery Form Validate() - Default Text
I am validating a bunch of text boxes but these boxes have a default value using a text water mark if they are empty. How do I create the validation rule so that it ignores a single default value?
Originally the default value of these text boxes were all different (default value stored in ToolTip tag), then I realized it would be a lot easier if they were just all the same value.
Here is my code:
// You can specify som开发者_StackOverflow中文版e validation options here but not rules and messages
$('form').validate();
// Add a custom class to your name mangled input and add rules like this
$('.username').rules('add', {
required: true,
messages: {
required: 'Some custom message for the username required field'
}
});
I had a similar problem, and I am using a jQuery watermark plugin. I do not ignore the values, but remove the watermark from on submission.
<input type="submit" value="Send Message" onclick="javascript:RemoveWatermarks();" />
<script type="text/javascript">
$(document).ready(function() {
$(function() {
$("#Name").watermark({
watermarkedClass: "WaterMark",
watermarkedText: "Your name"
});
});
});
function RemoveWatermarks() {
$("#Name").removeWatermark();
}
</script>
Obviously this is functionality tied to the specific watermark plugin I am using, but I figure this method would work with any watermark plugin that has a remove
function.
精彩评论