HTML Forms Validation

classic Classic list List threaded Threaded
2 messages Options
Erick Mugoma Erick Mugoma
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

HTML Forms Validation

Hi,
Am trying to enable and disable specific fields based on the option selected by the user. For example I've list of options to select when the user comes to a clinic e.g scheduled appointment, Late appointment or early appointment. if the user selects late or early appointment I want to enable a date field that allows him/her to enter the date of scheduled appointment. this date field should be enabled only when the user selects late or early appointment otherwise this field is disabled.
I've written a JQuery code below but it is not working. U'll notice I've written three attempts.

            <tr>
                <td>Schedule Status:</td>
                <td>
            <obs id="schedule" conceptId="1501" answerConceptIds="1493,1494,1942,1913"
                  answerLabels="Scheduled,Unscheduled,Follow up visit,Late Appointment"/>
          <script type="text/javascript">            
          $j(document).ready( function(){
             $j("#schedule").change(function() {
                var sel=$j("#schedule option:selected").val();
                if (sel!=1913) //late or early appointment then
                {
                    var input = $j("#apptDate").get();
                    input.attr("disabled", true); //attempt 1
                    $j("#apptDate").attr('disabled', 'disabled'); //Attempt 2
                    $j("#apptDate").attr("disabled", "disabled"); //Attempt3
                }
               
               
          });
           
            });
          </script>
         </td>
                <td><obs id="apptDate"  conceptId="5096" labelText="If early or late: Scheduled Appointment Date:" disabled="disabled"/></td>
            </tr>

Kindly let me know if there are other ways I can go about it.

I'll be interested in learning more on how to validate different fields in HTML forms.
This is very key to our openmrs implementations
We are using HTML Form entry module version 1.9.3 module running on OPENMRS 1.8.3.

Thanks

Erick

[hidden email] from OpenMRS Implementers' mailing list
Mark Goodrich-2 Mark Goodrich-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: HTML Forms Validation

Erick--
 
Have you taken a look at the Javascript reference page for Html Form Entry?  Specifically, have you tried using the getField function?  There might be some issues with usnig this methods with an obs of type date, but I think this is something we may have recently fixed.
 
<a href="https://wiki.openmrs.org/display/docs/HTML&#43;Form&#43;Entry&#43;JavaScript&#43;Reference">https://wiki.openmrs.org/display/docs/HTML+Form+Entry+JavaScript+Reference
 
Mark
 
 
 

From: [hidden email] [[hidden email]] On Behalf Of Erick Mugoma [[hidden email]]
Sent: Friday, May 18, 2012 1:47 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] HTML Forms Validation

Hi,
Am trying to enable and disable specific fields based on the option selected by the user. For example I've list of options to select when the user comes to a clinic e.g scheduled appointment, Late appointment or early appointment. if the user selects late or early appointment I want to enable a date field that allows him/her to enter the date of scheduled appointment. this date field should be enabled only when the user selects late or early appointment otherwise this field is disabled.
I've written a JQuery code below but it is not working. U'll notice I've written three attempts.

            <tr>
                <td>Schedule Status:</td>
                <td>
            <obs id="schedule" conceptId="1501" answerConceptIds="1493,1494,1942,1913"
                  answerLabels="Scheduled,Unscheduled,Follow up visit,Late Appointment"/>
          <script type="text/javascript">            
          $j(document).ready( function(){
             $j("#schedule").change(function() {
                var sel=$j("#schedule option:selected").val();
                if (sel!=1913) //late or early appointment then
                {
                    var input = $j("#apptDate").get();
                    input.attr("disabled", true); //attempt 1
                    $j("#apptDate").attr('disabled', 'disabled'); //Attempt 2
                    $j("#apptDate").attr("disabled", "disabled"); //Attempt3
                }
               
               
          });
           
            });
          </script>
         </td>
                <td><obs id="apptDate"  conceptId="5096" labelText="If early or late: Scheduled Appointment Date:" disabled="disabled"/></td>
            </tr>

Kindly let me know if there are other ways I can go about it.

I'll be interested in learning more on how to validate different fields in HTML forms.
This is very key to our openmrs implementations
We are using HTML Form entry module version 1.9.3 module running on OPENMRS 1.8.3.

Thanks

Erick

[hidden email] from OpenMRS Implementers' mailing list

[hidden email] from OpenMRS Implementers' mailing list
Loading...