Selective JQuery validation

Posted by TenaciousImpy on Stack Overflow See other posts from Stack Overflow or by TenaciousImpy
Published on 2010-04-04T20:47:12Z Indexed on 2010/04/04 20:53 UTC
Read the original article Hit count: 296

Hi,

I'm using JQuery Validation to validate a particular textbox in my form. The textbox is an optional website section, which uses the url validation method. This works fine and validates accordingly. I would like to have http:// preset into the textbox, to save the user having to type it. However, when the text is set, the validator becomes 'active', and prevents anything on the form being submitted until either the http:// is manually removed, or a valid website is entered. Is there a way of preseting text into the textbox, which won't cause the validator to start validating?

I tried to use

$("[id$='tbWebsite']").val("http://");

just before I call form.validate(), but it doesn't work (i.e. it still gets checked).

I've never used JQuery Validator before, so hopefully there's a fix for this that I'm missing!

An alternate solution for my case in particular, could be to activate the validator if a certain button is pressed (instead of any button on the form). Would that be possible?

Thanks

© Stack Overflow or respective owner

Related posts about jquery-validate

Related posts about ASP.NET