A limitation with using Checkboxes in LANSA for Web

Date:3 July, 2005
Product/Release:LANSA for Web
Abstract:A workaround to a limitation with using checkboxes in a LANSA for Web application.
Submitted By:LANSA Technical Support
Last Review:December 2010

Many people wish to use checkboxes in their application developed for LANSA for Web. This is a great way of enhancing the presentation of the application, but developers should be aware of a limitation in the interaction between the browser and the Web server when using checkboxes.

Please note the following:

  1. This limitation is not imposed by LANSA for Web but if the workaround below is used this issue can be circumvented.
  2. The following workaround has also been included in the most recent LANSA for Web documentation
  3. This technique cannot be used in browselists.

In HTML syntax, the user cannot define a value for the ON (selected) state for the checkbox element. The browser only sends back a value for the checkbox if it is selected. This means that if the checkbox is not selected, no value is sent back by the browser.

This field can be visualized as a checkbox, by using the following HTML:

<INPUT TYPE="CHECKBOX" NAME="RFLD" VALUE="Y">

If a field is visualized as a checkbox by just using the above HTML, problems will occur if the initial value of the field is to set the checkbox ON (selected). If the user unchecks the checkbox, no value is sent back by the browser. This means that the application will not know that the field has been unchecked.

To overcome this problem use a combination of a ‘dummy' field and a JavaScript function.

The checkbox Visual Web component would contain the following:

<INPUT TYPE="HIDDEN" NAME="RFLD" VALUE="<RDML MERGE="RFLD">" SIZE=1>
		<INPUT TYPE="CHECKBOX" NAME="DUMMY" onClick="SetState(this, RFLD, ‘Y', ‘N') ">
		<SCRIPT>
		if (document.LANSA.RFLD.value=="Y") document.LANSA.DUMMY.checked=true
		</SCRIPT>

In the above example, RFLD is the actual name of the field to be visualized as a checkbox. Instead of visualizing this field as a checkbox, it is defined to be hidden in the HTML. A ‘dummy' field is used to visualize the checkbox. When the user clicks on the checkbox, a JavaScript function, SetState, is called to set the value of the actual field, RFLD.

The initial value of RFLD is read as a result of the <RDML MERGE="RFLD"> LANSA tag. The JavaScript function will set the state of the checkbox (the DUMMY field), dependent on the initial value of RFLD.

In this example, it is assumed that a value of ‘Y' is the checked state. When the checkbox is unchecked the value is ‘N'.

Note that the HTML for the Web component is not encapsulated by the <RDML CHECKVALUE> and </RDML> LANSA tags. It is the JavaScript function attached to the Web component which sets the initial state of the checkbox.

The SetState JavaScript function is used by the DUMMY field to set the value of the actual field RFLD. The third parameter of this function is the value for the checked state whilst the fourth parameter is for the unchecked state.

The SetState JavaScript function can be embedded into the DEFAULT_SCRIPT page:

Function SetState(obj, RFld, chkValue, unchkValue)
		{
		    if (obj.checked)
		        RFld.value=chkValue
		    else
		        RFld.value=unchkValue
		}

When the HTML form is submitted, the value attached to the RFLD field is returned to the application. The value attached to the DUMMY field is irrelevant since it is not used in the RDML function.