473,804 Members | 3,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Recover checkboxes on pageload

57 New Member
I understand there are several ways to save checkbox information. The way that best fits this application is validating on the divID but the function is still not working.

Expand|Select|Wrap|Line Numbers
  1. function checkCB() {
  2.           var inputs = document.getElementById(Filtered).getElementsByTagName('input');
  3.            for (var i=0; i<inputs.length ; i++)
  4.                {
  5.                var obj = inputs[i];
  6.                if(inputs[i].type == "checkbox") {
  7.                inputs[i].checked=false;
  8.                }
  9.            }
  10.       }
  11.  
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <input 
  4.     type="checkbox"
  5.     class="checkbox"
  6.     id="Filtered"
  7.     name="title"
  8.     value="false"
  9.     /> 
  10.       title 
  11.  
Jan 23 '08 #1
11 1867
acoder
16,027 Recognized Expert Moderator MVP
"Filtered" should be in quotes.
Jan 24 '08 #2
keydrive
57 New Member
I managed to get the field in the URL showing the correct value onsubmit and the view source is correct as well. But the checkbox itself remains empty.


Expand|Select|Wrap|Line Numbers
  1. function checkCB() {
  2.       var inputs = document.getElementById("Filtered").getElementsByTagName('input');
  3.         for (var i=0; i<inputs.length ; i++)
  4.                {
  5.          var obj = inputs[i];
  6.         if(inputs[i].type == "checkbox") {
  7.          inputs[i].checked="false"; 
  8.                }
  9.            }
  10.        }
  11.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. <body onload="checkCB()"> 
  3.  
  4. <%     
  5. String title = request.getParameter("title");
  6.         if (title != "false") 
  7.         {
  8.     title = "true";
  9.         }
  10. %>
  11.  
  12. <input                    
  13.         type="checkbox"
  14.     class="checkbox"
  15.     id="Filtered"
  16.     name="title"
  17.     value="<%=title %>"
  18.        />     
  19.     title 
  20.  
Jan 24 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
Filtered is the name of the checkbox, so if you try to get the input elements from there, you won't get anything. Look for the parent element container for the checkbox and then use getElementsByTa gName.
Jan 25 '08 #4
keydrive
57 New Member
I do appreciate your feedback aCoder although I'm not sure I understand what I need to key in on.
Jan 25 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
What exactly is checkCB() supposed to do? In your code, setting checked to false would mean that the checkbox is unchecked.
Jan 25 '08 #6
keydrive
57 New Member
Once the checkbox is checked, the form is submitted to a second form. The second form includes the checkbox and I need it to be checked or unchecked depending on the user selection.

I must be getting mixed up if I am setting the box to false in my function.
Jan 25 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
In that case, you don't even need JavaScript (though you could use JavaScript too).

A checkbox is only passed through if it is checked, so in your JSP code, check that the value exists. If it does, set the checked attribute to "checked" or "true" for the checkbox using JSP.
Jan 25 '08 #8
keydrive
57 New Member
I have this working but is there a cleaner way to recheck checkboxes on pagination?

Expand|Select|Wrap|Line Numbers
  1. <%
  2. String[] categories = request.getParameterValues("category");
  3.         String category = "";
  4.     if(categories != null)
  5.     {
  6.         for(int ii = 0; ii < categories.length; ii++)
  7.         {
  8.         category += categories[ii];
  9.         }
  10.                 }
  11. %>
  12. <div class="item">
  13.      <input 
  14.     type="checkbox"  
  15.     id="cb1" 
  16.     name="category"
  17.     value="cb1"
  18.     <%  if (categories.indexOf("cb1") == -1) {%>
  19.     <%  } else { %>
  20.     checked="yes"
  21.     <% } %>
  22.         Checkbox 1
  23. </div>
  24. <div class="item">
  25.      <input 
  26.     type="checkbox"  
  27.     id="cb2" 
  28.     name="category"
  29.     value="cb2"
  30.     <%  if (categories.indexOf("cb2") == -1) {%>
  31.     <%  } else { %>
  32.     checked="yes"
  33.     <% } %>
  34.        Checkbox 2
  35. </div>
  36.  
Mar 12 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
The cleaner way would be to only check if checked:
Expand|Select|Wrap|Line Numbers
  1.      <input 
  2.     type="checkbox"  
  3.     id="cb1" 
  4.     name="category"
  5.     value="cb1"
  6.     <%  if (categories.indexOf("cb1") != -1) {%>
  7.     checked
  8.     <% } %>>
  9.         Checkbox 1
  10.  
Don't forget to close the tag.
Mar 12 '08 #10

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

Similar topics

5
3830
by: Prem K Mehrotra | last post by:
I come from Oracle background. In Oracle, when one wants to do a point in time recovery, one can specify recover database until timestmap. Oracle's database maps to a db2 subsystem, i.e., in Oracle database means entire database, i.e.. all tablespaces (including indexes). I see only recover tablespace and recover indexspace (or index) commands in db2. Therefore, one has to specify all the tablespaces and indexspaces and recover them
3
3174
by: apple | last post by:
UDB v8 fp 6a on AIX 5.1.0.0 Below is a manual incremental recover from compressed backup datasets. With external compress backup datasets, can it be coded to do an automatic incremental recover? The manual incremental recover works just fine, but having trouble getting the automatic incremental recover to work. Thanks for your help # INCREMENTAL BACKUP
10
4601
by: Steven | last post by:
I create the checkboxes dynamically on my webform (aspx). after I create them, when I check any of the checkboxes, nothing happens. Here is my code ... ArrayList LayerNameList1 = LayerNameList; CheckBox checkBoxArray; int BoxCount = 0; HtmlTableRow newRow; HtmlTableCell FieldCell;
0
961
by: Stephan Bour | last post by:
Hi, I have a query page were users can check previous orders according to a number of parameters. The query results are presented in a datalist and the datasource is a sql query. Since I capture the user name at logon, I thought I¹d provide a default datalist with all the orders for that particular user at pageload. In that case, I don't need to display the name information for the user in the datalist. However, I need to keep the Name...
2
1294
by: Stephan Bour | last post by:
I repost this since I know how much some list people hate html posts ;-) Hi, I have a query page were users can check previous orders according to a number of parameters. The query results are presented in a datalist and the datasource is a sql query. Since I capture the user name at logon, I thought I¹d provide a default datalist with all the orders for that particular user at pageload. In that case, I don't need to display the name...
3
1087
by: Antoine | last post by:
Is there anything that can make my project run its pageload twice? I added trace lines throughout code, and then checked recently. Unless its a temporary issue (resolved by reboot etc) I definitely seem to see pageload trace item being fired more than once, and a sizeable delay for it to run through all the functions its already processed (on first load anyway)! I doubt it is going this in my development environment, in fact I am...
4
2408
by: epigram | last post by:
I've got a page that has a Panel object that I am dynamically adding CheckBox controls to. The number of CheckBox controls and the name of each control is based on a database query. I would like to know how I can query for all the CheckBox controls on the page during postback and check their checked attribute without using the name of each checkbox. I want to do this in a generic way so that I don't have to requery the db or save the...
4
1385
by: Wayne Wengert | last post by:
I have a form that has a cbo set to TabIndex 0 (it is the only item set to tabindex 0). On page Load if I step through the code that cbo LostFocus event fires after other initializations are completed and after the LostFocus event completes, that cbo gets focus and the form opens? Why is that LostFocus event firing? Any hints on how to debug this? Wayne
0
1798
by: mike_dba | last post by:
I have been testing the db2 recover command on a DB2 V8.2 Linux database. The database contains a single partition. I am not archiving logs but retaining them on disk. the backup image is to disk as well. I performed the following in order : 1. OFFLINE BACKUP <time#1> 2. Create table S.T (c1 smallint) 3. Insert several rows into S.T - values 1,2,3,4,5 4. ONLINE BACKUP <time#2> 5. Insert several more rows 6,7,8,9
1
2451
by: Chris Date | last post by:
Hi I´ve got a problem with my scrollable table. It´s a weekscheduler table with 7 columns ( weekdays ) and dynamicaly rows ( time ). So the rows starts at 0:00am and ends at 12:00pm ( 24:00h ). There is a value in the database, with a timeshift value ( in minutes ). For example, timeshift value = 480 (480: 60 = 8) --> set scrollbar to 8:00am. How can i set the scrollbar by pageload to the timeshift value? Here 2 jpgs about the scheduler...
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9591
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10594
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10331
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.