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
7 2235
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
-
function checkPreviousItems() { //call this where you need
-
for (var i=0; i<PreviousItems.length; i++)
-
document.getElementById(PreviousItems[i]).checked = true;
-
}
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. - <script language="javascript">
-
var ids = [];
-
var preids = [];
-
var PreviousItems= new Array();
-
function cancel()
-
{
-
for (var i=0; i<arry.length; i++)
-
document.tcol.getElementById(PreviousItems[i]).checked = true;
-
}
-
-
function show()
-
{
-
-
txt="";
-
btn="";
-
ids=[];
-
preids=[];
-
coffee=document.forms['tcol'].coffee;
-
for (i=0;i<coffee.length;++ i)
-
{
-
if (coffee[i].checked)
-
{
-
txt=txt + coffee[i].id;
-
btn = 't'+ coffee[i].id;
-
prebtn = coffee[i].id;
-
ids[i]=btn;
-
preids[i]=prebtn;
-
}
-
}
-
PreviousItems = preids;
-
}
-
</script>
-
-
<input type='checkbox' name='coffee' id='col1' value='Unit1' checked />
-
<input type='checkbox' name='coffee' id='col2' value='Unit2' checked />
-
<input type='checkbox' name='coffee' id='col3' value='Unit3' checked />
-
<input type='checkbox' name='coffee' id='col4' value='Unit4' checked />
-
<input type='checkbox' name='coffee' id='col5' value='Unit5' checked />
-
<input type='checkbox' name='coffee' id='col6' value='Unit6' checked />
-
<input type='checkbox' name='coffee' id='col7' value='Unit7' checked />
-
-
<p><input type='button' onclick='show()' value='Save'> <input type='button' onclick='cancel()' value='Cancel'></p>
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.
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
- var txt;
-
var ids[];
-
var PreviousItems= new Array();
-
function cancel() {
-
for (var i=0; i<PreviousItems.length; i++)
-
document.getElementById(PreviousItems[i]).checked = true;
-
}
-
-
function show() {
-
txt="";
-
ids = [];
-
coffee=document.tcol.coffee; //are you sure its forms['tcol'] and not tcol?
-
for (var i=0;i<coffee.length;++ i) {
-
if (coffee[i].checked) {
-
txt += coffee[i].id; //is this really needed?
-
var temp = ids.push('t'+ coffee[i].id);
-
temp = PreviousItems.push(coffee[i].id);
-
}
-
}
-
}
Also change the names of checkboxes from coffee to coffee[ ]
Thanks it has worked out.
Thanks it has worked out.
Good to hear that. :)
Post again in case of any other problem.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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 =...
|
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++)...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |