growth Posted May 5, 2006 Share Posted May 5, 2006 To know how many checkbox there are in my array of checkbox, I use :var c = document.AlterarExcluirForm.checkbox;var tam = c.length;But, my array is dynamic, and when I have just one checkbox in the array, the command c.length doesn´t works.How can I resolve that ?Thanks. Link to comment Share on other sites More sharing options...
raimo Posted May 6, 2006 Share Posted May 6, 2006 To know how many checkbox there are in my array of checkbox, I use :var c = document.AlterarExcluirForm.checkbox;var tam = c.length;But, my array is dynamic, and when I have just one checkbox in the array, the command c.length doesn´t works.How can I resolve that ?Thanks.<{POST_SNAPBACK}> To know how many checkboxes You have You shoud do something like:<form id="AlterarExcluirForm" action="#"><input type="checkbox" /><input type="checkbox" /><input type="checkbox" /></form><script type="text/javascript">var cnt = 0;var inp = document.getElementById("AlterarExcluirForm").elements; // all inputsfor (var i = 0; i < inp.length; i++) if (inp[i].getAttribute("type") == "checkbox") cnt++;alert(cnt); //there is 3 checkboxes now</script> Link to comment Share on other sites More sharing options...
growth Posted May 8, 2006 Author Share Posted May 8, 2006 Thank you for the answer.But I have to use the code below too, to know wich checkbox is selected : for ( var i=0; i < c.length; i++ ){ if ( c.checked == true ) { tem_selecao = true; break; }}But, when I have just one checkbox, this code doesn´t work. Link to comment Share on other sites More sharing options...
growth Posted May 8, 2006 Author Share Posted May 8, 2006 Thank you for the answer, and sorry for didn´t show you my complete code.I have to use the code below, to know wich checkbox is selected.With your solution, I will resolve the problem with the command c.length.But I still have a problem with the command "c.checked", when I have just one checkboxvar c = document.AlterarExcluirForm.checkbox;for ( var i=0; i < c.length; i++ ){if ( c.checked == true ){tem_selecao = true;break;}} Link to comment Share on other sites More sharing options...
miteshbhimjiyaani Posted May 9, 2006 Share Posted May 9, 2006 Thank you for the answer, and sorry for didn´t show you my complete code.I have to use the code below, to know wich checkbox is selected.With your solution, I will resolve the problem with the command c.length.But I still have a problem with the command "c.checked", when I have just one checkboxvar c = document.AlterarExcluirForm.checkbox;for ( var i=0; i < c.length; i++ ){if ( c.checked == true ){tem_selecao = true;break;}}<{POST_SNAPBACK}> hi,some modification alert(inp.checked);<form id="AlterarExcluirForm" action="#"><input type="checkbox" checked/><input type="checkbox" /><input type="checkbox" /></form><script type="text/javascript">var cnt = 0;var inp = document.getElementById("AlterarExcluirForm").elements; // all inputsfor (var i = 0; i < inp.length; i++)if (inp[i].getAttribute("type") == "checkbox"){ alert(inp[i].checked);cnt++;}alert(cnt); //there is 3 checkboxes now</script> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now