• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checkbox in JSP

 
Sudhin Moorkoth
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
When a checkbox is checked, I want no action to tak place even if user wants to uncheck it. I want this to be accomplished without disabling the checkbox. I am looking for a javascript code onclick event. Any help will be appreciated.
Sudhin
 
Sunetra Saha
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this :
function Check()
{
if (document.form.check != "true")
{
document.form.check.checked = "true";
}
}
where "true" is the checked value of the checkbox
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or how about this?
<input type=checkbox checked=true onclick="this.checked=true;">
 
Sudhin Moorkoth
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The checkbox is checked on certain conditions. Part of JSP is included.
I am able to get proper value for isEditRequested. But, the getter for addrForMail returns null. I need to disallow user to uncheck the checkbox if isEditRequested is true and addForMail contains a value (in this case "Yes")
Sorry about the cryptic code.

</TD>
<SCRIPT LANGUAGE="Javascript">
var editRequest = "<%= facade.isEditRequested() %>";
</SCRIPT>
The above Javascript gets me correct value.
</TR>
<TR HEIGHT="35">
<TD BGCOLOR="#EEEEE0" ALIGN="left" WIDTH="180"><IMG WIDTH="10" SRC="/csdops/images/utility/clrpix.gif"><B>Address for Mail:</B>
<BR><IMG WIDTH="10" SRC="/csdops/images/utility/clrpix.gif"><FONT SIZE="1">Program mail will be sent here</FONT></TD></TD>
<TD BGCOLOR="#EEEEE0" ALIGN="left"><INPUT TYPE="checkbox" ID="addrForMail" NAME="addrForMail" VALUE="Yes" <%= facade.isEditRequested() ? ((facade.getCurrentMailingAddressSeq()) ==(facade.getSeqNbr())) ? "CHECKED" :"" : ""%> " onClick="return isChecked("<%= facade.getAddrForMail() %>",editRequested);"></TD>
</TR>

</TABLE>
</TD></TR>

<TR><TD > </TD></TR>
<SCRIPT LANGUAGE="Javascript">
var mailAddr = "<%= facade.getAddrForMail() %>";
</SCRIPT>
This always returns null;
Sudhin
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this javascript/jsp mix can be made a lot simpler, but perhaps I'm missing something.

Within your jsp code, perform all of your logic required to determine whether or not:
1. the textbox is checked
2. the textbox should *remain* checked

Based on these results, use two variable (one for each condition above) with two possible values.

Simply output these variable between < %= % > tags in the main body of your HTML.. this eliminates the nasty looking code in the form.

My thoughts are something like this:In regards to your method returning null... I can't see where you use any of your javascript variables anyways, probably in parts of the page you don't post. And I'm not sure what the facade object is, but are you sure that it isn't 'properly' returning null? Maybe it is null.
[This message has been edited by Mike Curwen (edited August 01, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic