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

Checkboxes from an array

25
i want to chech thoes chekboxes which are sored in an array,

i.e. there is an array PreviousItems[] = [col1,col2,,col4,,,col7,,,,col11,col12,,]

want to checked thoes checkboxes in the form whoes id are stored in array PreviousItems.

i.e.
[HTML]<input type='checkbox' name='coffee' id='col1' value='Unit' checked />
<input type='checkbox' name='coffee' id='col2' value='Unit' checked />
<input type='checkbox' name='coffee' id='col3' value='Unit' unchecked />
<input type='checkbox' name='coffee' id='col4' value='Unit' checked />
<input type='checkbox' name='coffee' id='col5' value='Unit' unchecked />

[/HTML]Simillarly
Feb 21 '08 #1
7 2235
hsriat
1,654 Expert 1GB
i want to chech thoes chekboxes which are sored in an array,

i.e. there is an array PreviousItems[] = [col1,col2,,col4,,,col7,,,,col11,col12,,]

want to checked thoes checkboxes in the form whoes id are stored in array PreviousItems.

i.e.
<input type='checkbox' name='coffee' id='col1' value='Unit' checked />
<input type='checkbox' name='coffee' id='col2' value='Unit' checked />
<input type='checkbox' name='coffee' id='col3' value='Unit' unchecked />
<input type='checkbox' name='coffee' id='col4' value='Unit' checked />
<input type='checkbox' name='coffee' id='col5' value='Unit' unchecked />

Simillarly

Expand|Select|Wrap|Line Numbers
  1. function checkPreviousItems() { //call this where you need
  2.    for (var i=0; i<PreviousItems.length; i++) 
  3.    document.getElementById(PreviousItems[i]).checked = true;
  4. }
Feb 22 '08 #2
rupak
25
Actually i want to store the checkboxes selected on Save button, and on modification of cehckxboxes want to Cancle so the previous set will be checked again, means previous condition will be retrived.

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. var ids = [];
  3. var preids = [];
  4. var PreviousItems= new Array();
  5. function cancel()
  6. {
  7. for (var i=0; i<arry.length; i++) 
  8. document.tcol.getElementById(PreviousItems[i]).checked = true;
  9. }
  10.  
  11. function show()
  12. {
  13.  
  14. txt="";
  15. btn="";
  16. ids=[];
  17. preids=[];
  18. coffee=document.forms['tcol'].coffee;
  19. for (i=0;i<coffee.length;++ i)
  20. {
  21.  if (coffee[i].checked)
  22. {
  23. txt=txt + coffee[i].id;
  24. btn = 't'+ coffee[i].id;
  25. prebtn = coffee[i].id;
  26. ids[i]=btn;
  27. preids[i]=prebtn;
  28. }
  29. }
  30. PreviousItems = preids;
  31. }
  32. </script>
  33.  
  34. <input type='checkbox' name='coffee' id='col1' value='Unit1' checked />
  35. <input type='checkbox' name='coffee' id='col2' value='Unit2' checked />
  36. <input type='checkbox' name='coffee' id='col3' value='Unit3' checked />
  37. <input type='checkbox' name='coffee' id='col4' value='Unit4' checked />
  38. <input type='checkbox' name='coffee' id='col5' value='Unit5' checked />
  39. <input type='checkbox' name='coffee' id='col6' value='Unit6' checked />
  40. <input type='checkbox' name='coffee' id='col7' value='Unit7' checked />
  41.  
  42. <p><input type='button' onclick='show()' value='Save'> <input type='button' onclick='cancel()' value='Cancel'></p>
Feb 22 '08 #3
hsriat
1,654 Expert 1GB
Try the following changes..
line 8: document.getElementById(PreviousItems[i]).checked = true;
line 34 onwards: <input type='checkbox' name='coffee[]' id='col1' value='Unit1' checked />

And I'm sorry I didn't get your algorithm.
Feb 22 '08 #4
rupak
25
Try the following changes..
line 8: document.getElementById(PreviousItems[i]).checked = true;
line 34 onwards: <input type='checkbox' name='coffee[]' id='col1' value='Unit1' checked />

And I'm sorry I didn't get your algorithm.

Actually there are lots of checkboxes which are default checked and then have two buttons
SAVE and CANCEL

Once the user changed the present condition of the checkboxes it need to be stored, thus on SAVE we store the modified condition in an array.

Else if user modified the present condition wrongly and then want to keep the previous one he need to CANCEL it. And then do the correct modification and SAVE them.

According to the SAVED value we have to print the checkboxes Value
Feb 22 '08 #5
hsriat
1,654 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. var txt;
  2. var ids[];
  3. var PreviousItems= new Array();
  4. function cancel() {
  5.     for (var i=0; i<PreviousItems.length; i++) 
  6.     document.getElementById(PreviousItems[i]).checked = true;
  7. }
  8.  
  9. function show() {
  10.     txt="";
  11.     ids = [];
  12.     coffee=document.tcol.coffee; //are you sure its forms['tcol'] and not tcol?
  13.     for (var i=0;i<coffee.length;++ i) {
  14.         if (coffee[i].checked) {
  15.             txt += coffee[i].id; //is this really needed?
  16.             var temp =  ids.push('t'+ coffee[i].id);
  17.             temp = PreviousItems.push(coffee[i].id);
  18.         }
  19.     }
  20. }
Also change the names of checkboxes from coffee to coffee[ ]
Feb 22 '08 #6
rupak
25
Thanks it has worked out.
Feb 27 '08 #7
hsriat
1,654 Expert 1GB
Thanks it has worked out.

Good to hear that. :)

Post again in case of any other problem.
Feb 27 '08 #8

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

Similar topics

0
by: Frank Collins | last post by:
Can anyone point me to some good examples on the web of using values from dynamically created checkboxes on forms in ASP, particularly relating to INSERTING those values into a SQL or Access...
8
by: Ralph Freshour | last post by:
I have multiple checkbox's created with an array name because I have many on the same web page - their names are like: frm_chk_delete frm_chk_delete frm_chk_delete frm_chk_delete etc. Here...
5
by: @(none) | last post by:
I have a page which is a set of CheckBoxes generated daily and thus the number of Checkboxes changes each day. What I want to do is allow the user to select one or more checkboxes and the push a...
4
by: Erwin Moller | last post by:
Grrr, Forgive my ranting, but this really irritated me a lot. <ranting> I have a page with X checkboxes with the same name. code like: var numberofCB =...
6
by: terence.parker | last post by:
I currently have the following JS in my header: function checkall(thestate) { var checkboxes=eval("document.forms.EssayList.file_id") for (i=0;i<checkboxes.length;i++)...
5
by: Craig Lister | last post by:
Newish to c# - Coming from Delphi. I'd like to add 255 checkboxes to a screen at runtime, and name then cb1, cb2... cb255 The code below does not work, but, how can I get this to work? public...
8
by: Tim | last post by:
On my form I have 10 checkboxes named chkbox1,chkbox2,....chkbox10. I would have like to set it up as an array control like in VB6 where I could have chkbox(1),chkbox(2) but I think .net you have...
3
sunbin
by: sunbin | last post by:
Hi, I am having in a Trouble when working with dynamic checkboxes (i.e. checkboxes with the same name, e.g. <input type="checkbox" name = "check" value="dynamic integer value">) I have...
1
by: Anuj | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the...
16
by: sarega | last post by:
Hi, There is an array whose length varies dynamically on the users input, I have to provide checkboxes for this array along with the value of the array and based on the checkboxes selected by the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.