Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using JQuery rules

Status
Not open for further replies.

GezH

Programmer
Aug 7, 2002
68
Hello.

I am making changes to a JSP page with javascript validation via JQuery. Currently the validate method defines a number of rules, for example:

rules: {
"card.cardName": "required",
"card.cardType": "required"}
},
messages: {
"card.cardName": "Please enter the name on the card",
"card.cardType": "Please select a card type"}
}

I want to add some extra rules for new form fields which I have added. However, I only want this validation to happen if a certain checkbox is checked. I've not used JQuery before, so I don't know if this is possible or how I could do it?

Any advice greatly appreciated.
 
I'm quite new to jQuery but it looks to me like you are using a jQuery plugin and you've only posted a small part of your code.

Could you post the entire jQuery code please? Also try using [ignore]
Code:
...
[/ignore] tags as it makes reading much easier for people trying to help.

You might find additional help at jQuery site, they have excellent documentation and examples for all native jQuery functions as well as in depth info on any plugins.


As an outside guess (without seeing the code) you could try wrapping your validation code within a standard jQuery check. Something like

Code:
if($('#mycheckbox').val()=='checked'){
    do your validation stuff here
}


--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Hmm... without meaning to sound sarcastic, that's pretty obvious!

What I'm asking is, whether I can put code like that into the JQuery rules. So, in pseudocode, my script would do the following:

rules: {
"card.cardName": "required",
"card.cardType": "required",
"myNewFormValue": "required": BUT ONLY IF THE CHECKBOX IS CHECKED!}
},
 
what are the 'jQuery rules'?

Like I said, it looks like you are using a plugin. What you can put in the 'rules' and the format in which that can be done depends on how the plugin is set up.

Your question is psuedocode, so by it's nature - yes you can do it. How exactly you implement it is another question for which it would help to see the actual code.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top