Validating via JavaScript
This document will explain how to create a JavaScript function for validity checking. For basic information regarding validity checking please see this document.
The purpose of this JavaScript is to check to see if the start date is less than the end date.
Note: This is a very simple example that is meant to demonstrate how to create and setup a JavaScript function. Your JavaScript function could be designed to check for your specific needs!
Using JavaScript in Maintenance Applications
The source code for the Maintenance JavaScript used in this example can be found here.
In the example provided, we check to see if field STARTDATE, from Maintenance #230 is greater than the ENDDATE field. If it is, we force the browser to return the message "Start Date is greater than End Date" and we disallow the form from submitting, allowing the user to correct their mistake. If STARTDATE is less than or equal to ENDDATE, no message will be seen and the browser will submit the form to the database.
Compile your maintenance application, then open m-Painter. Click the "Source" button" and add the code referenced above directly before the </head>
tag.
Note: If you are using the Work-with Maintenance template, do not forget to switch to the "Maintain" page before going into Source view.
Note: Be sure to replace all reference of 00230 with your 5 digit application number. Also, be sure to replace references of STARTDATE & ENDDATE with your appropriate fields.
Lastly, add the following code: onsubmit="return validate_form();"
to the <form>
tag.
Before making changes to the form tag:
After making changes to the form tag:
When I run my application and attempt to enter invalid data, I am presented with one of the following screens:
Using JavaScript in Report Prompt pages
The source code for the Report JavaScript used in this example can be found here.
In the example provided, we check to see if field R001, from Report #230 is greater than the R002 field. If it is, we force the browser to return the message "Start Date is greater than End Date" and we disallow the form from submitting, allowing the user to correct their mistake. If R001 is less than or equal to R002, no message will be seen and the browser will submit the form to the database.
Compile your Report, then open m-Painter. Change the page drop down, to Prompt. Click the "Source" button" and add the code referenced above directly before the </head>
tag.
Note: Be sure to replace all reference of 00230 with your 5 digit application number. Also, be sure to replace the pre-defined references of R001 and R002 with the correct Record Selection numbers for your scenario.
Lastly, add the following code: onsubmit="return validate_form();"
to the <form>
tag.
Before making changes to the Report prompt form tag:
After making changes to the Report prompt form tag:
When I run my report and enter invalid data, I am presented with one of the following screens: