Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
172
rated 0 times [  173] [ 1]  / answers: 1 / hits: 31056  / 10 Years ago, wed, november 26, 2014, 12:00:00

I have form on page1.php:



<form method=POST action=page2.php>
<input type=checkbox name=F10 id=f10>
<input type=checkbox name=W10 id=w10>
<input type=checkbox name=F20 id=f20>
<input type=checkbox name=W20 id=w20>
<input type=checkbox name=F30 id=f30>
<input type=checkbox name=W30 id=w30>
</form>


I want to diable a checkbox if another checkbox is checked using javascript or XMLHttpRequest().
I tried doing it using javascript but it didn't work.



if(document.getElementById(f10).checked){
document.getElementById(w20).disabled=true;
}

More From » php

 Answers
4

You can use regular javascript to get a true or false value for checked for example,



var isChecked= document.getElementById('elementName').checked;
if(isChecked){ //checked
//execute code here
}else{ //unchecked
//execute code here
}


or if you want whenever the checkbox check is changed



var checkbox = document.getElementById('elementName');
checkbox.addEventListener(change, functionname, false);

function functionname(){
var isChecked = checkbox.checked;
if(isChecked){ //checked

}else{ //unchecked

}
}

[#68685] Tuesday, November 25, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lelasamiraa

Total Points: 208
Total Questions: 99
Total Answers: 107

Location: Uzbekistan
Member since Tue, Nov 30, 2021
3 Years ago
;