m-Power Documentation

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 DATEORD, from Maintenance #230 is greater than the DATEEXP 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 DATEORD is less than or equal to DATEEXP, 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 DATEORD & DATEEXP with your appropriate fields.

Lastly, add the following code: onsubmit="return validate_form();" to the <form tag.

Before making change to form tag:

After making change to form tag:

When I run my application and attempt to enter an invalid date, I am presented with this screen:

Using JavaScript in Report Prompt pages

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 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 change to Report prompt form tag:

After making change to Report prompt form tag:

When I run my application and attempt to enter an invalid date on my prompt page, I am presented with this screen:


subscribe to newsletter
Want to receive weekly insight, tips, viewpoints, and news from a 28-year industry veteran? Enter your email below to subscribe!

m-Power Customers

Customers


mrc (US)
555 Waters Edge
Suite 120
Lombard, IL 60148
630-916-0662
mrc (UK)
Argyle House
1 Dee Road
Richmond, Surrey
TW9 2JN
+44-20-8322-7720