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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Checkbox problem

Status
Not open for further replies.

tavie

Technical User
Nov 23, 2001
79
0
0
US
Hope someone can help... I have a web page that is generated from a SQL table. it creates an HTML table with values from the table and each row contains a check box. The problem is how do I enumerate which check box is checked using a button control given that the table will vary in the number of checkboxes...I know I need a sub routine but how will I format it since I do not know the number of records I will have until after the script has executed
 
No worries... given a simple HTML table with 3 rows in it:
Code:
<table id="specials">
<tr><td>One</td></tr>
<tr><td>Two</td></tr>
<tr><td>Three</td></tr>
</table>
You can use this javascript function to find out how many rows (<tr>) there are in the table:
Code:
<script type="text/javascript">
function countRows() {
  var ourTable = document.getElementById('specials');
  var collectionOfRows = ourTable.getElementsByTagName('tr');
  return collectionOfRows.length;
}
</script>
And of course you might have a link on your page that you clicked to trigger the function... a bit like this:
Code:
<a href="#" onclick="alert(countRows());return false;">Count them</a>
I'm sure your task can be achieved using the same kind of technique. Maybe you could extend the function to accept the unique ID of any table... maybe add in some error checking etc.

Let us know how you get on.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Thank you... Will this work behind an HTA application ??

also.. I need to know whether each check box is checked by clicking on a button on the page how is that done.. do i need to use a form??
 
Yes to both or just the HTA question... I have been unable to figure out how to use a button to process the values of all dynamic checkboxes and determine whether they are checked or unchecked ???
 
Yes it will work with an HTA application. You would be using a form to include the checkboxes (since you must include form elements within a form declaration to maintain a compliant DOM).

You can add a class to each checkbox, then use document.getElementsByTagName('input') to get a collection of all the input elements on the page... and then iterate through this collection testing the classname of each element... if it matches your class, then you could test the checked property of the checkbox to determine if it is checked.

Let us know how you go!
Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Can you provide a quickie example ?? I am new to forms and classes...I have never needed them in the past, now I am learning...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top