quanghoc
asked on
get all checkbox status in a form
I don't have much time to research about Javascript. However, I have a good knowledge about programming generally. Here is the description of my problem:
+ Given a form name 'myform'
+ Given multiple checkbox with different id name
+ Perform a loop to scan through all available checkboxes in the form and see if the checkbox is check, then get the value in put into a string 'str'. The seperator string is "|||". If the checkbox is uncheck, then do nothing.
The things that I don't know is how to scan through the form and "know" all the checkboxes and get the value/status of it. Please help. Thanks.
+ Given a form name 'myform'
+ Given multiple checkbox with different id name
+ Perform a loop to scan through all available checkboxes in the form and see if the checkbox is check, then get the value in put into a string 'str'. The seperator string is "|||". If the checkbox is uncheck, then do nothing.
The things that I don't know is how to scan through the form and "know" all the checkboxes and get the value/status of it. Please help. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This was perfect. Thank you.
<!--
function fnTest()
{
var lmax = document.forms[0].elements
var lCounter;
var element;
var str = "" ;
for (lCounter=0; lCounter < lmax; lCounter++)
{
element = document.forms[0].elements
if (element.type == "checkbox")
{
if (element.checked)
{
if (str == "")
{
str = "true";
}
else
{
str = str + "|||true";
}
}
}
}
return str;
}
//-->
</SCRIPT>