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

Recover checkboxes on pageload

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 1849
acoder
16,027 Expert Mod 8TB
"Filtered" should be in quotes.
Jan 24 '08 #2
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 Expert Mod 8TB
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 getElementsByTagName.
Jan 25 '08 #4
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 Expert Mod 8TB
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
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 Expert Mod 8TB
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
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 Expert Mod 8TB
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
a few more lines of code you've cleaned up for me... and counting.

Thanks for the reply.
Mar 14 '08 #11
acoder
16,027 Expert Mod 8TB
You're welcome!
Mar 16 '08 #12

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

Similar topics

5
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...
3
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?...
10
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;...
0
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...
2
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...
3
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...
4
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...
4
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...
0
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...
1
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 )....
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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
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,...

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.