You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Mike R. Phelan" <mr...@vsticorp.com> on 2004/03/02 20:56:22 UTC

pure Struts implementation of form with an html:checkbox that enables/disables an html:text ?

Hi all,

Is there a better way to use a checkbox to dynamically disable/enable a text box, within a form?
I want the end user to be unable to fill out the text field until after she has "checked" the check box.
I would prefer not to use javascript. Is there a "pure Struts" way to do this?
My searches have come up with some vaguely related material, but nothing that provides a javascript-free solution.

the jsp:
...
<body>
<script>
function GrayOut(obj_checkbox)
{
  if(obj_checkbox.checked)
  {
    obj_checkbox.form.boundIP.disabled = false;
  }
  else
  {
    obj_checkbox.form.boundIP.disabled = true;
  }
}
</script>

...
<html:form action="/NewIPRecordSubmit" focus="baseIP">
...
IP Address
...
<html:text property="baseIP" styleClass="textbox" style="size:114"/>
...
<html:checkbox property="ipRangeEnabled" value="no" onclick="GrayOut(this)"/>
Upper Range <html:text property="boundIP" styleclass="textbox" style="size:114" disabled="true" />
...
</html:form>
</body>

thanks,

Mike Phelan

ps - I got the javascript from this site:
http://www.faqts.com/knowledge_base/view.phtml/aid/13354/fid/310