Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
177
rated 0 times [  179] [ 2]  / answers: 1 / hits: 90627  / 13 Years ago, wed, june 1, 2011, 12:00:00

This is my checkbox HTML code



<input id=termsCheckbox name=termsCheckbox type=checkbox value=terms <?PHP echo $terms; ?> class=checkbox>


this is javascript code



var terms = $(#termsCheckbox);

function validateTerms(){
if(termsCheckbox.checked == false){
terms_div.addClass(terms_error);
return false;
}
else{
terms_div.removeClass(terms_error);
return true;
}
}


I want to check whether checkbox checked or not and if not add a class to terms_div. Please help me to solve this problem. thanks


More From » checkbox

 Answers
10

You need to access the className variable (pure JS) the following assumes your div has an ID of terms_div, that terms_error is the only class you might want on the div, and that you setup your checkbox with onClick=validateTerms();



function validateTerms(){
var c=document.getElementById('termsCheckbox');
var d=document.getElementById('terms_div');
if (c.checked) {
d.className='';
return true;
} else {
d.className='terms_error';
return false;
}
}

[#91925] Tuesday, May 31, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
isaacvalentinn

Total Points: 325
Total Questions: 120
Total Answers: 131

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
isaacvalentinn questions
Mon, Jan 18, 21, 00:00, 3 Years ago
Mon, Nov 23, 20, 00:00, 4 Years ago
Wed, Sep 23, 20, 00:00, 4 Years ago
;