Thanks Darius for the quick help!  Everything works except the form is
eventually submitted and the message goes away without the user clicking
it.  The problem is probably with the event.preventDefault(); function.

 

I tried the following with the same results...

event.stopPropagation();

and
return false;

 

Do you have any suggestions?

 

I've tried it with Firefox 7.0.1 and got the above behavior.  With IE9,
it waits for the user to click "OK" and acknowledge the message before
submitting the form.

 

Thanks,

James

 

From: [email protected] [mailto:[email protected]] On
Behalf Of Darius Jazayeri
Sent: Wednesday, November 09, 2011 11:55 AM
To: [email protected]
Subject: Re: [OPENMRS-IMPLEMENTERS] HTML Form Entry - How to run
Javascript just before the form is submitted

 

Hi James,

 

Something like this should work:

 

<htmlform>

...

<submit submitClass="submitButton"/>

...

<script>

$j(function() {

    $j('.submitButton').click(function(event) {

        if ( /* do some logic here */ ) {

            window.alert("Cannot submit because XYZ");

            event.preventDefault();

        }

    });

});

</script>

</htmlform>

 

-Darius

On Wed, Nov 9, 2011 at 8:32 AM, James Arbaugh <[email protected]>
wrote:

I need to require another field to be entered if a date field has a
value.  Is there a way to trigger a Javascript when the submit button is
clicked, before the form is accepted?

 

To be more specific, I need to require the hospital discharge status
field to be filled out if the form has a discharge date.  If the
discharge date is set, but the discharge status is empty I want to give
an error message and not accept the form.  I can't simply set the field
as required because the form is only partially filled out at the time of
admission.  The discharge date and discharge status are not known at
that time.

 

Thanks,

James

 

 

________________________________

Click here to unsubscribe
<mailto:[email protected]?body=SIGNOFF%20openmrs-implement-l>
from OpenMRS Implementers' mailing list

 

________________________________

Click here to unsubscribe
<mailto:[email protected]?body=SIGNOFF%20openmrs-implement-l>
from OpenMRS Implementers' mailing list 


_________________________________________

To unsubscribe from OpenMRS Implementers' mailing list, send an e-mail to 
[email protected] with "SIGNOFF openmrs-implement-l" in the  body 
(not the subject) of your e-mail.

[mailto:[email protected]?body=SIGNOFF%20openmrs-implement-l]

Reply via email to