Problem:
This is a Web demo which demonstrates the use of COBOL to validate FORM input fields and uses JavaScript to display an error message place focus on the filed in error.
Resolution:
INTRODUCTION
============
This Web program demonstrates the use of a COBOL CGI program to do validation of the form input fields. If an error is encountered, a message box (alert) is displayed thru the web page and focus is placed on the input field in error. To do this, three hidden input fields are used on the web page: one (errors) that will be toggled between "y" or "n" to denote if an error exists, one (msg) that contains the error message to be displayed, and one (focusfld) to contain the name of the input field to place the focus on. The COBOL program populates the three hidden fields. Javascipt is used to check if the errors field is "y" and displays an alert message if true.
Notice the onload parameter of the BODY tag in the html. It mentions the Javascript function body1_onload_func(), which is executed when the page loads.
<BODY id=body1 onload=body1_onload_func(); name = body1>
The body1_onload_func Javascript function declares a variable called errorField, which is assigned the value of the focusfld hidden input field. An if test checks the value of the errors hidden field. If it is "y", the alert function is used to display the value of the msg hidden field. The eval function is used to string together a statement that executes the focus method of the object (input field) that is the value in errorField. This places the focus on the input field in error.
function body1_onload_func()
{
var errorField = form1.focusfld.value;
if ( form1.errors.value == "y" )
{
alert( form1.msg.value );
eval( "form1." errorField ".focus();" );
}
...
SOURCE FILES:
==========
Program Files Description
---------------- -----------------------------------------------------------
cobolval.cbl COBOL program that validates form fields.
Copy Files:
---------------- -----------------------------------------------------------
cobolval.cpf Defines external-form for html fields.
cobolval.cpy Defines internal cobol items that relate to html fields.
cobolval.cpv Data conversion and initialization code. cobolval.htm Embedded html.
Form Files:
---------------- -----------------------------------------------------------
cobolval.mff Form Designer file.
REQUIREMENTS:
==========
*** IMPORTANT!!! When running this app from a debug build, be sure to copy the data files (sales.dat and sales.idx) to the debug subdirectory.
OPERATION:
========
When valid values are entered for each of the form fields and submitted, a sales amount is returned. Valid values for the REPID fields are 101, 102, or 103. Valid values for the Month field are 01 - 03, and valid values for the State fields are PA, NJ, or NY. Try other values to see the warning messages that will be displayed.
==========================================================
Keywords: demonstration, sample, example, demo, web programming, cobolval.zip
demo.ex
demo.ne
demo.se