views:

32

answers:

1

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 some 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'
    }
});
A: 

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.

Dustin Laine
I'm not actually using the watermark plug. I am doing this:http://www.dotnetcurry.com/ShowArticle.aspx?ID=427I'm going to switch to the Watermark plugin since it looks much easier to use.How do you add the watermarks back if the page does not validate?
Scott
I don't because the error message that I put up next to the input field states the field name. I am sure you can hook into some validation event to show those again, sorry I could not help on that part.
Dustin Laine