Friday, September 12, 2008

How to get value from Checkboxlist using javascript

I read many of the thread regarding to how to get value from the check box list using javascript.....

Here i am describing how you get the value from the check box list using javscript

JavaScript
----------
function getName1()
{

var chkText = '';
var chktable = document.getElementById('chklistInterests');
var chktr = chktable.getElementsByTagName('tr');

for(var i=0; i ;lt chktr.length;i++)
{
var chktd = chktr[i].getElementsByTagName('td');
for(var j=0; j
;lt chktd.length; j++)
{
var chkinput = chktd[j].getElementsByTagName('input');
var chklabel= chktd[j].getElementsByTagName('label');
for(k=0;k ;lt chkinput.length;k++)
{
var chkopt = chkinput[k];
if(chkopt.checked)
{
chkText = chkText + chklabel[k].innerText + ',';
}
}
}
}
alert( chkText);
}

3 comments:

Arvind said...

hi vipul,
Thanks for above code.
but this code works only for IE and doesnt work for Firefox. Update this if u have any idea ..

Tatayya Torlapati said...

use innerHTML instead of innerText, it will works for you.

Dhaval thakor said...

try this one http://www.webdevelopersnotes.com/tips/html/finding_the_value_of_a_checkbox.php3