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.
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.
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:addvali dation(thi s.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
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:addvali
<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
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" />
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Example at the following address are not sufffisant ?
http://api.jquery.com/addClass/
http://api.jquery.com/removeClass/
Regards