Hi James, The problem is the submit button already has an onClick defined. You could probably achieve what you're trying to do with some hacky jquery that removes any existing onClick on the submit button, and then you'd have to call submitHtmlForm() from your own javascript. (Sorry, don't have time to look up what that code would look like.)
The better solution already has a ticket: https://tickets.openmrs.org/browse/HTML-195 -Darius On Wed, Nov 9, 2011 at 10:38 AM, James Arbaugh <[email protected]>wrote: > 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<[email protected]?body=SIGNOFF%20openmrs-implement-l>from > OpenMRS Implementers' mailing list > **** > > ** ** > ------------------------------ > > Click here to > unsubscribe<[email protected]?body=SIGNOFF%20openmrs-implement-l>from > OpenMRS Implementers' mailing list > **** > ------------------------------ > Click here to > unsubscribe<[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]

