473,388 Members | 1,286 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,388 software developers and data experts.

Show and Hide Table Column related to checked checkboxes

25
Hi!

I have a multiple selection of checkboxes

[HTML]<input type='checkbox' name='coffee' id='col1' value='Address'/>
<input type='checkbox' name='coffee' id='col2' value='Name'/>
<input type='checkbox' name='coffee' id='col3' value='ID'/>
<input type='checkbox' name='coffee' id='col4' value='UserName'/>
<input type='checkbox' name='coffee' id='col5' value='Code'/>
[/HTML]
Want to store them in array. On submit of button.
Then hide and show the table column with respect to selection of checkboxes. i.e. selected checkbox will show that columns in table resat will hide.

[HTML]<td id="col1">Address</td>
<td id="col2">Name</td>
<td id="col3">ID</td>
<td id="col4">UserName</td>
<td id="col5">Code</td>[/HTML]

thus if checkbox for "Name" and "ID" are checked than it will show the Columns only for "Name" and "ID" rest will hide but will be done on submit of the button
Feb 11 '08 #1
13 7478
ronverdonk
4,258 Expert 4TB
For a correct interpretation your ID's must be unique. In IE you will get away with it (most of the time) but not in FF.

ROnald
Feb 11 '08 #2
rupak
25
How can i proceed with the code for the same with the modified id for table cell ie. tcol1, tcol2.
[HTML]<form>
<input type='checkbox' name='coffee' id='col1' value='Address'/>
<input type='checkbox' name='coffee' id='col2' value='Name'/>
<input type='checkbox' name='coffee' id='col3' value='ID'/>
<input type='checkbox' name='coffee' id='col4' value='UserName'/>
<input type='checkbox' name='coffee' id='col5' value='Code'/>
<input type='button' onclick='show()' value='Save'>
</form>

<td id="tcol1">Address</td>
<td id="tcol2">Name</td>
<td id="tcol3">ID</td>
<td id="tcol4">UserName</td>
<td id="tcol5">Code</td>
[/HTML]
Onclick on Save button I should be able to store the checked checkbox an then show the related columns in table, rest hidden. In next cycle the modified checked checkboxes again stored new one and previous cleened and thus the show respected column.
Feb 12 '08 #3
acoder
16,027 Expert Mod 8TB
You might not even need JavaScript for this if you're going to submit the form. Is the page going to be refreshed?
Feb 12 '08 #4
rupak
25
Yes need to refresh the page, thus only current set of the checkboxs will be stored on Save Button Clicked. Thus showing thoes colums only
Feb 12 '08 #5
acoder
16,027 Expert Mod 8TB
Does this need to be done in JavaScript or will any language do?
Feb 12 '08 #6
rupak
25
it should be done with Javascript.
Feb 12 '08 #7
acoder
16,027 Expert Mod 8TB
Then, in that case, it'd be better if this was done without refreshing the page, e.g. on clicking the checkbox.
Feb 12 '08 #8
rupak
25
It is already available at

http://www.fiendish.demon.co.uk/html...tablecols.html
Feb 12 '08 #9
acoder
16,027 Expert Mod 8TB
So does that solve your problem?
Feb 12 '08 #10
rupak
25
this does not solve my problem,

as i had an Edit Button onclick it show and hide a div, which has all the checkboxes with submit button.

With tabuler columns.

Once we select the checkboxes Click on Submit Button then store all the checked checkboxes and hide the div

then the stored checkboxes show the respective column in ntable.

Again on Click Edit it should show all the checked checkboxes, if we edit them then we have to submit it again else it will show the same as previous.

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.  
  3. var  fieldsArray = new Array();
  4.  
  5.  
  6. var showMode = 'table-cell';
  7. if (document.all) showMode='block';
  8. function show()
  9. {
  10.  
  11.     fieldsArray= new Array();
  12.     txt="";
  13.     cells="";
  14.     {
  15.     coffee=document.forms[0].coffee;
  16.     for (i=0;i<coffee.length;++ i)
  17.         {
  18.         if (coffee[i].checked)
  19.             {
  20.             txt=txt + coffee[i].id;
  21.             btn = 't'+ coffee[i].id;
  22.             cells = cells + btn;
  23.             fieldsArray[i]=btn;
  24.             }
  25.  
  26.         }
  27. toggleview('div1');
  28.     }
  29. mode = coffee.checked ? showMode : 'none';
  30. }
  31. function toggleview(element1)
  32. {
  33. element1 = document.getElementById(element1);
  34. if (element1.style.display == 'block' || element1.style.display == '')
  35. element1.style.display = 'none';
  36. else
  37. element1.style.display = 'block'; 
  38. }
  39. </script>
Not able to complete the Full funcnality as need you help on it.
Feb 12 '08 #11
acoder
16,027 Expert Mod 8TB
Again on Click Edit it should show all the checked checkboxes, if we edit them then we have to submit it again else it will show the same as previous.
So, if I understand correctly, this is where the problem lies. If you don't submit, it won't be updated. Is that correct? If not, could you show the code that you call when clicking Edit.
Feb 13 '08 #12
rupak
25
Yes you got the problem, the code on Edit is

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function toggleview(element1)
  3. {
  4. element1 = document.getElementById(element1);
  5. if (element1.style.display == 'block' || element1.style.display == '')
  6. element1.style.display = 'none';
  7. else
  8. element1.style.display = 'block'; 
  9. }
  10. </script>
Feb 13 '08 #13
acoder
16,027 Expert Mod 8TB
So how do call this function?

PS. please use code tags when posting code. Thanks!
Feb 13 '08 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Edward | last post by:
The below code creates an HTML form that's comprised of 2 tables. There is an onClick function in each table that checks or unchecks all checkboxes in the table. The code is basically a trimmed...
2
by: Edward | last post by:
The below code builds 2 tables 4 rows by 4 cols. All cells have checkboxes. When checked, the checkboxes in the first column automatically check the remainder of the check boxes in the same row. ...
9
by: sergio | last post by:
Hi all, I have created the following script that will show/hide a menu based on checkboxes. It works fine in Opera but not on IE6! Does anybody knows a workaround this problem? Thanks for your...
5
by: Zambien | last post by:
Hi all, Here's my problem. I have tables that are using the menu/submenu idea for hiding rows. This works fine in IE (of course) and does show/hide correctly in netscape, but as soon as the...
2
by: MOHSEN KASHANI | last post by:
Hi, I am trying to hide some form elements in a form by default and show/hide depending on which radio button is clicked. This is what I have but it is not working: <head> <style> ..noshow {...
4
by: jerryyang_la1 | last post by:
I've found this script that allows be to hide/show form elements.. <script language="JavaScript"><!-- var toggle = true; function show(object) { if (document.layers && document.layers)...
2
by: avanti | last post by:
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...
8
by: Axelar | last post by:
Hi :) i've found a usefull script : http://www.editeurjavascript.com/scripts/scripts_formulaires_3_786.php but if i do the same with my form inserted in a table then it doesn't work anymore. ...
0
Frinavale
by: Frinavale | last post by:
This code snippet is just a little bit of fun. It demonstrates how you use JavaScript and CSS to show or hide columns in a table depending on whether or not a checkbox corresponding with the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.