Saturday, January 8, 2011

JavaScript to enable/disable textbox on checkbox checked/unchecked.

In many application you might be needed to enable/disable the text box property based on certain condition. For example in many web site you might be seen based on check box selection their is changes in text box enable/disable property.



Other City : <input type="checkbox" id="chkbxType" onclick="getCheckfDesc();" />
<input type="text" id="CheckDesc" disabled="disabled" /></td>

function getCheckfDesc()
{
var i = document.getElementById("chkbxType").checked;
document.getElementById("CheckDesc").disabled = !i;
}

Saturday, January 1, 2011


JavaScript to check all check box


This script is used to check all check box at once. In most of application you might be required to check all check box on one click. For example in Gmail if you want to delete all mail you just need to select Delete All check box which will automatically select all check box of inside table/grid.




In image given above you can seen in Image 1 that first check box is common, on checking it all other check box will get checked automatically as shown in Image 2. The main use of this script is to do this process faster then instead of going to perform this process on server side which take little time to do it.


<input id="checkall" type="checkbox" onclick="selectall(this.checked);"/> <font>Select All</font>

function selectall(chkval)
{
var grid = document.getElementById('<%=gridABC.ClientID %>');
var chk= grid.getElementsByTagName("input");
for(var count=0; count<chk.length;count++)
{
if(chk[count].type=='checkbox')
chk[count].checked=chkval;
}
}