473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Checkboxes inside the Table Cells

Hi,

I add rows to my table dynamically, with a checkbox in each row in the
first column. The checkbox in the header row acts as a 'Select All'
checkbox. Whenever it is checked, checkboxes in all the rows get
checked. I tried this with changing the innerXML of the cell - but it
is not a very elegant solution.

What would be the best way to do this?

Thanks,
Avanti

Apr 19 '07 #1
2 7058
On Apr 20, 2:39 am, avanti <ava...@gmail.comwrote:
I add rows to my table dynamically, with a checkbox in each row in the
first column. The checkbox in the header row acts as a 'Select All'
checkbox. Whenever it is checked, checkboxes in all the rows get
checked. I tried this with changing the innerXML of the cell - but it
is not a very elegant solution.
I don't think mine is the best way, but here it is.
Change the checked property of checkbox in each row with the 'Select
All' checkbox's checked value.

function checkAll(elm) {
var cb=elm.form.getElementsByTagName('input');
var x=cb.length;
while (x--)
if (cb[x].type=='checkbox'&&cb[x].name!='selectAllCheckbox')
cb[x].checked=elm.checked;
}

<input type="checkbox" name="selectAllCheckbox"
onclick="checkAll(this);">

HTH

Apr 20 '07 #2
On Apr 20, 5:39 am, avanti <ava...@gmail.comwrote:
Hi,

I add rows to my table dynamically, with a checkbox in each row in the
first column. The checkbox in the header row acts as a 'Select All'
checkbox. Whenever it is checked, checkboxes in all the rows get
checked. I tried this with changing the innerXML of the cell - but it
is not a very elegant solution.
No, it's not. innerXML? Or do you mean Microsoft's proprietary
InnerXml?
>
What would be the best way to do this?
You could start with something like:

<script type="text/javascript">

var util = {};

util.getCheckboxes = function(el){
var elements = el.getElementsByTagName('input');
var t;
var checkboxes = [];
for (var i=0, len=elements.length; i<len; i++){
t = elements[i];
if ('checkbox' == t.type){
checkboxes.push(t);
}
}
return checkboxes;
}

util.checkall = function(el){
var cbs = util.getCheckboxes(el.form);
var checked = el.checked;
var i = cbs.length;
while(i--){
cbs[i].checked = checked;
}
}

</script>

<form action="">
<table>
<tr>
<td><input type="checkbox" onclick="util.checkall(this);">
<td>Check/uncheck all
<tr><td><input type="checkbox"><td>cb0
<tr><td><input type="checkbox"><td>cb1
<tr><td><input type="checkbox"><td>cb2
<tr><td><input type="checkbox"><td>cb3
</table>
</form>
--
Rob

Apr 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul Thompson | last post by:
When I put a <div ...> inside a <table> specification, functionality is not there. When I put the <table> inside the <div> everything works. Why is that?
8
by: Jukka K. Korpela | last post by:
I just noticed that most browsers render <table border="1"><tr><td><p>foo</p></td></tr></table> the same way as <table border="1"><tr><td>foo</td></tr></table> That is, they ignore the p...
3
by: ryan.mclean | last post by:
Hi all, I hope somebody here can help me, I am attempting to obtain a reference to the anchors inside of a table. Here is what I have: table = document.getElementById(a_strTableId); for(var i...
2
by: john | last post by:
I posted this question to comp.lang.javascript but didn't get a response, so I'll try here. I am using ASP.NET and I have a datagrid. One of the columns in my grid is all checkboxes. When the...
6
by: Slim | last post by:
Accessing textboxes inside a table. I am trying to access controls in a table like this customerLastSales.Rows(i).Cells(j).Controls(0) but asp.net says...
5
by: Klaus Jensen | last post by:
Hi I am not sure, what is the best way to do this, and I hope somebody can offer some advice. :) I have 30 brands (from one table) out of one axis and 30 product categories (from another...
0
by: krokador | last post by:
This is doing my head in... We're starting to migrate our report-printing and such (forms included) to pdf - using xml files and nFOP with asp.net. In this case I have to print out a form which...
5
by: Test | last post by:
Is it possibel to have DIV's inside a table cell so that their position can be given relative to top left corner of the cell. Now the DIVs seem to position themselves relative to previous object.
8
by: PeteOlcott | last post by:
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/grid/tests/test_change_structure.html I would like to completely understand how GUI controls such as this one are constructed. In the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.