Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

addClass removeClass in JQuery

Hello Eperts,
I have two Text (not required) fields.  But if one field has a value, the other is required.  I have to use jQuery as all other validations are done using jQuery.  Could you please provide me a good example?  Thank you in advance.
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Hello RadhaKrishnaKiJaya,

Example at the following address are not sufffisant ?
http://api.jquery.com/addClass/
http://api.jquery.com/removeClass/

Regards
Avatar of NishchayaAndrew
NishchayaAndrew

Hello RadhaKrishnaKiJaya,

you can do this by Javascript. what you have to do is just add the html event to first textbox & one js function to force your jquery valdator mathod to check both control .

if you add onblur event to first textbox, like in first text box

<input type="text" id="txt1" onbulr="javascript:addvalidation(this.value)"............../>

<input type="text" id="txt2" ............../>

now in your JS block

function addvalidation(val)
{
           if (val !="")
           {
                  //put the some flag for ur jquery validator here. so this + txt2 control is also get check  
                 // before  submit like one global var chkboth=true;
           }else{
                 //remove the flag value  like our global var chkboth=false;
}
}


hope above is helpful.

Cheers
Avatar of RadhaKrishnaKiJaya

ASKER

Hi leakim971,  Thank you for your response.  I  looked at your links.  Not the one I wanted in fact.  I need to use addClass / removeClass with text fields.  Please let me know if you any other idea.  Thank you very much for your help.
Seems I don't understand but what about :


$('#mytextfieldid').addClass('myClass yourClass');

your textfield like that :

<input type="text" id="mytextfieldid" />

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of chuckalicious
chuckalicious
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial