• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Uncheck the checkbox

 
shruti patel
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shruti which back button are you talking about?? The one on the browser or you have created a custom back button on third.jsp??
 
shruti patel
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The one which i create custom back button .
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic