I have 1 checkbox in my sharepoint list with other columns. If checkbox value equal to 'true' i need to display some other controls, otherwise these controls should be hidden.
I open the New/Edit Item Aspx Page in Edit In Advance Mode add the Following script
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("hideFieldsOnStart");
function hideFieldsOnStart() {
//hide the control at start
var control = getTagFromIdentifierAndTitle("input","TextField","Percent");
control.parentNode.parentNode.parentNode.style.display="none";
//add an onchange event to the dropdown
getTagFromIdentifierAndTitle("input","RadioButtons","IsPercent").onchange = function() {ChangeEvent()};
}
function ChangeEvent()
{
//get the dropdown
var dropDown = getTagFromIdentifierAndTitle("input","DropDownChoice","IsPercent");
//get the selected value
var option = dropDown.options[dropDown.selectedValue].text;
alert(option)
//get the control
var control = getTagFromIdentifierAndTitle("input","TextField","Percent");
//show hide based on your condition
if(option == "true")
{
control.parentNode.parentNode.parentNode.style.display="";
}
else
{
control.parentNode.parentNode.parentNode.style.display="none";
}
//this gets the field based on title identifier and tagname
function getTagFromIdentifierAndTitle(tagName, identifier, title) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
return tags[i];
}
}
return null;
}
</script>
I use this code, when i checked textfield is disable but not check textfield is diable.