aspose file tools*
The moose likes Struts and the fly likes How to Uncheck the checkbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to Uncheck the checkbox" Watch "How to Uncheck the checkbox" New topic
Author

How to Uncheck the checkbox

shruti patel
Ranch Hand

Joined: Mar 10, 2008
Posts: 52
Hi friends,

In my Struts Application, i am Using check boxes in some jsp .
The problem which i am facing i will explain with below example.

for example:

i have three JSP's called "first.jsp","second.jsp","third.jsp"
from the "first.jsp" if i hit next button it goes to "second.jsp" in which i have a bunch of
Check boxes which should default to checked and i hit next it goes to "third.jsp" , then i hit back
it should come back to "second.jsp".but now the check boxes should be unchecked .


the problem i am facing is not able to uncheck the checkbox when i come back.


Presently i calling addOnLoadFunction(checkAll) to check all. because of this addOnLoadFunction().the check boxes are
checked when i come back..which i do not want to happen. should be unchecked.



Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

shruti which back button are you talking about?? The one on the browser or you have created a custom back button on third.jsp??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
shruti patel
Ranch Hand

Joined: Mar 10, 2008
Posts: 52
The one which i create custom back button .
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

This is a javascript problem rather than Struts. You have a method which is called on page load which checks all the checkboxes. To disable this, you must create your JSP such that it only calls the addOnLoadFunction on page load when it receives a parameter for example runOnload=true. Then on first.jsp you would call second.jsp as second.jsp?runOnload=true and from third.jsp, you would call second.jsp without parameter...
shruti patel
Ranch Hand

Joined: Mar 10, 2008
Posts: 52
function checkAll()
{


var chkBox = document.forms['orderData'].elements, z = 0;
for(z=0; z<chkBox.length;z++)
{
if(chkBox[z].type == 'checkbox' && chkBox[z].name != 'replaceChkBoxHeader')
{
chkBox[z].checked = true;
}
}

}
function uncheckAll()
{
var chkBox = document.forms['orderData'].elements, z = 0;
for(z=0; z><chkBox.length;z++)
{
if(chkBox[z].type == 'checkbox' && chkBox[z].name != 'replaceChkBoxHeader')
{
chkBox[z].checked = false;
}
}
}

addOnloadFunction(checkAll);


><div class="button_table">
<html:button styleClass="button" value="checked" property="replaceall" onclick="checkAll(this);" ><util:msg key="order.label.replaceall" /></html:button>
<html:button styleClass="button" value="unChecked" property="replacenone" onclick="uncheckAll(this);" ><util:msg key="order.label.replacenone" /> </html:button>
</div>

this is the code which i implemented..as i am calling addOnloadFunction as checkAll, so when i hit back button,the page reload and call again the checkAll. but i do not wnat check box to be checked.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

This is still a JavaScript issue and not Struts, as far as I can tell.

The JavaScript would not have passed a code review where I've worked--you've essentially written the exact same function twice. They differ by a single boolean value. For the sanity of those around you, refactor:Better yet, use a JavaScript library and reduce the code to a single line (here it's jQuery):Behold the magic:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Uncheck the checkbox
 
Similar Threads
making all fields empty when i make new transaction
jsppage not rfreshing inIE6.0
select and unselecting checkboxes based on clicking a check box
How to display two different jsp pages in one consolidated jsp page
struts-html:checkbox default checked