Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

counting random checkboxes values

Status
Not open for further replies.

Fursten

Programmer
Dec 27, 2000
403
PT
Hi,

I have one table with an aleatory number of rows. Each row have, for exemple, two columns in witch I have created, with a loop, one checkbox for each column (the ID for each checkbox is assigned with the for... next cycle).

So, the final result is something like this:

Table-Title

Columnn1 Column2
Line1 checkbox(ID=11) checkbox(ID=21)
Line2 checkbox(ID=12) checkbox(ID=22)
..... ............... ...............
Total: (nº of checked checkebox) (nº of checked checkebox)

What I need is to be able to count the number of checked checkboxs that the user have selected, and put the total at the final of each column. Note that I don´t know how many checkedboxes I will have... that´s way the Id of each of them is assign with a for cycle...

How can I make this?

Thank you in advance :)

Ps: For instance, is this possible to manage with the "getTableByTagName, or any other method of the table object? Where can I find good information about the methods of this object?
 
<html>
<table>
<tr>
<td>el 1<input type=CHECKBOX id=i01 onclick=&quot;count(this)&quot;></td>
<td>el 10<input type=CHECKBOX id=i10 onclick=&quot;count(this)&quot;></td>
</tr>
<!--.....-->
<tr>
<td>el 9<input type=CHECKBOX id=i09 onclick=&quot;count(this)&quot;></td>
<td>el 19<input type=CHECKBOX id=i19 onclick=&quot;count(this)&quot;></td>
</tr>
<tr>
<td><div name=&quot;d1&quot; id=&quot;d1&quot;>0</div></td>
<td><div name=&quot;d2&quot; id=&quot;d2&quot;>0</div>
</td>
</tr>
</table>
<script language=&quot;javascript&quot;>
var counter1=0;
var counter2=0;
function count(el)
{

if(el.id.substr(0,2)==&quot;i0&quot;)
{
if(el.checked) counter1+=1
else counter1-=1;
document.all.d1.innerText=counter1;
}
if(el.id.substr(0,2)==&quot;i1&quot;)
{
if(el.checked) counter2+=1
else counter2-=1;
document.all.d2.innerText=counter2;
}
}
</script>

</html>
 
Sorry, but I forgot to tell that the number of columns are random too....
Can I still use that method?
Thank you
 
is it printing the checkboxes to the page from a database?
 
No, Im making that table with the help of a XML tree...
Depending of that xml tree I create a table where in each row/column I create a checkbox, so the user can clik on it (check it) It´s like a questionare...

Thank you
 
if columns are unkown, and rows are unknown....will all columns and rows be equal in size? vs. column 1 has 25 rows, and column 2 has 76 rows?
 
Hi,

Yes, they will be equal in size.

Thank you :)

Sergio Oliveira
 
You could use that method but you have to generate all cell id some like &quot;i&quot;+number and generate script for each new &quot;i&quot;+number value... (it's quite complicated... but possible)
 
I'm workin on somthing for you...pretty busy with two other jobs, but as long as you're not in a terrible rush...I think I will probably be able to come up with somthing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top