Jump to content

HTML Table with Checkboxes


dave.robertson

Recommended Posts

Hello Everyone,I think I am missing a trick with HTML checkboxes and tables and I hope someone out there can put me on the right track.I am writing a simple HTA application that will query MS Active Directory for all users who have not logged on for a given period of time, and will return their name and last logon date to an HTML table, hence the post to this forum.I have written the code for that and all is well with the world.My problem is that I would like to include a checkbox in each resulting table row, allowing the row (user) to be 'selected'. Again I can add in the checkbox easily enough, but here comes the rub.Each checkbox will have an onclick="DoSomething" that will fire a sub routine to add/remove the user from an array/dictionary (haven't decided that bit yet), so my problem is, how can I give each checkbox a unique ID/Name, as the table is built dynamically and the contents will vary, and be able to check which row(s) have been selected?The script below is shows the sort of thing I am trying to achieve, and builds a simple table from a csv.txt file using an MS office control (I am using this as a proof of concept before stitching it into the main code).

<html><head><script language=vbscript>sub GetInfo' Add user to dictionary or somethingend sub</script>        </head><BODY><!-- Use MS Office Control to build table from CSV text file for testing--><OBJECT id="TableList" CLASSID="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83"> <PARAM NAME="DataURL" VALUE="d:\development\lastlogon\UserList.csv"> <PARAM NAME="UseHeader" VALUE="True"> <PARAM NAME="TextQualifier" VALUE=","></OBJECT><H2>Last Logon Report Test App</H2><table border='1' width='100%' cellspacing='0' datasrc=#TableList><THEAD><TR><td style="width: 55px">Select</td><TD>Name</TD><TD>Created</TD><TD>Last Logon</TD></TR></THEAD><TBODY><TR><!-- Need to figure out how to dynamically name this check box--><TD style="width: 55px"><input type="checkbox" onclick="getinfo" id="chk1"}/></TD><TD><B><DIV datafld="Name"></DIV></B></TD><TD><DIV datafld="Created"></DIV></TD><TD><DIV datafld="Last Logon"></DIV></TD></TR></TBODY></TABLE></BODY>

I hope someone out there can help, as this was supposed to be the easy bit that I left till last.-RedRobbo-

Link to comment
Share on other sites

you don't need to give a unique id, in fact you don't need to give them ID's at all. You can use the rowIndex property of the TR element to determine which row you are on. All you do is bubble up until you get to the row containing the checkbox. Here's one way

<table border='1' width='100%' itemspacing='0' datasrc=#tablelist id="myTable">	<tr>		<td style="width: 55px"><input type="checkbox" onclick="getinfo(this)" id="chk1"/></td>		<td><b><div datafld="name"></div></b></td>		<td><div datafld="created"></div></td>		<td><div datafld="last logon"></div></td>	</tr>	<tr>		<td style="width: 55px"><input type="checkbox" onclick="getinfo(this)" id="chk1"/></td>		<td><b><div datafld="name"></div></b></td>		<td><div datafld="created"></div></td>		<td><div datafld="last logon"></div></td>	</tr>	<tr>		<td style="width: 55px"><input type="checkbox" onclick="getinfo(this)" id="chk1"/></td>		<td><b><div datafld="name"></div></b></td>		<td><div datafld="created"></div></td>		<td><div datafld="last logon"></div></td>	</tr>	<tr>		<td style="width: 55px"><input type="checkbox" onclick="getinfo(this)" id="chk1"/></td>		<td><b><div datafld="name"></div></b></td>		<td><div datafld="created"></div></td>		<td><div datafld="last logon"></div></td>	</tr></table><script>	function getinfo(item)	{		while (item.tagName != "TR")		{			item = item.parentNode		}		alert(item.rowIndex)	}</script>

Link to comment
Share on other sites

Hello Everyone,I think I am missing a trick with HTML checkboxes and tables and I hope someone out there can put me on the right track.I am writing a simple HTA application that will query MS Active Directory for all users who have not logged on for a given period of time, and will return their name and last logon date to an HTML table, hence the post to this forum.I have written the code for that and all is well with the world.My problem is that I would like to include a checkbox in each resulting table row, allowing the row (user) to be 'selected'. Again I can add in the checkbox easily enough, but here comes the rub.Each checkbox will have an onclick="DoSomething" that will fire a sub routine to add/remove the user from an array/dictionary (haven't decided that bit yet), so my problem is, how can I give each checkbox a unique ID/Name, as the table is built dynamically and the contents will vary, and be able to check which row(s) have been selected?The script below is shows the sort of thing I am trying to achieve, and builds a simple table from a csv.txt file using an MS office control (I am using this as a proof of concept before stitching it into the main code).
<html><head><script language=vbscript>sub GetInfo' Add user to dictionary or somethingend sub</script>        </head><BODY><!-- Use MS Office Control to build table from CSV text file for testing--><OBJECT id="TableList" CLASSID="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83"> <PARAM NAME="DataURL" VALUE="d:\development\lastlogon\UserList.csv"> <PARAM NAME="UseHeader" VALUE="True"> <PARAM NAME="TextQualifier" VALUE=","></OBJECT><H2>Last Logon Report Test App</H2><table border='1' width='100%' cellspacing='0' datasrc=#TableList><THEAD><TR><td style="width: 55px">Select</td><TD>Name</TD><TD>Created</TD><TD>Last Logon</TD></TR></THEAD><TBODY><TR><!-- Need to figure out how to dynamically name this check box--><TD style="width: 55px"><input type="checkbox" onclick="getinfo" id="chk1"}/></TD><TD><B><DIV datafld="Name"></DIV></B></TD><TD><DIV datafld="Created"></DIV></TD><TD><DIV datafld="Last Logon"></DIV></TD></TR></TBODY></TABLE></BODY>

I hope someone out there can help, as this was supposed to be the easy bit that I left till last.-RedRobbo-

Sub is A vb property. Do not use this in JS.
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...