This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Servlets and the fly likes checkbox in JSP 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 » Java » Servlets
Bookmark "checkbox in JSP" Watch "checkbox in JSP" New topic
Author

checkbox in JSP

Sudhin Moorkoth
Greenhorn

Joined: Mar 29, 2001
Posts: 8
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

Joined: Feb 25, 2001
Posts: 77
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

Joined: Feb 20, 2001
Posts: 3695

or how about this?
<input type=checkbox checked=true onclick="this.checked=true;">
Sudhin Moorkoth
Greenhorn

Joined: Mar 29, 2001
Posts: 8
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

Joined: Feb 20, 2001
Posts: 3695

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).]
 
Don't get me started about those stupid light bulbs.
 
subject: checkbox in JSP
 
Similar Threads
Readonly Checkbox
html:checkbox
how to get values from checkbox
html:checkbox tag
Applet Project