JQuery Issue

56 views
Skip to first unread message

Tom Russell

unread,
Jun 26, 2013, 10:09:00 PM6/26/13
to web...@googlegroups.com
I cannot seem to get some jquery code to work right and not sure why. Basically when I click a checkbox I want another field to appear below that one.

This is my form code:

@auth.requires_login()
def register_patient():
    mark_not_empty(db.patient)
    mark_not_empty(db.emergencycontacts)
    mark_not_empty(db.dependents)
    db.patient.medical_record_number.default = 'KND' + str(date.today().year) + '0000' + str(random.randrange(1, 9999999+1))
    db.patient.medical_record_number.writable = False
    form=SQLFORM.factory(db.patient, db.emergencycontacts, db.dependents)

    fs0=form[0][:27]     #patient rows
    fs1=form[0][27:38]   #emergency contacts
    fs2=form[0][38:42]     #dependents
    fs3=form[0][-1]     # submit row (last)

    form[0]=TABLE(
    FIELDSET(TAG.legend("Patient Info"),TABLE(fs0),_id="register0"),
    FIELDSET(TAG.legend("Emergency Contact Info"),TABLE(fs1),_id="register1"),
    FIELDSET(TAG.legend("Dependents"),TABLE(fs2),_id="register2"),
    TABLE(fs3))
    if form.process().accepted:
        id = db.patient.insert(**db.patient._filter_fields(form.vars))
        form.vars.patient=id
        id = db.emergencycontacts.insert(**db.emergencycontacts._filter_fields(form.vars))
        id = db.dependents.insert(**db.dependents._filter_fields(form.vars))
        #form.vars.dependents=id
        # and get a list of all persons
        redirect(URL('manage_patients'))

    style = STYLE(""".not_empty {color:#d00;}""")

    return dict(form=DIV(style,form))

My html code:

{{left_sidebar_enabled=True}}
{{extend 'layout.html'}}

{{block left_sidebar}}
              <li><a href="/">Home</a></li>
              <!-- <li class="active"><a href="#">Admission</a></li> -->
              <li><a href="physician">Home(Physician)</a></li>
              <li><a href="frontdesk">Home(Front Desk)</a></li>
              <li><a href="nurse">Home(Nurse)</a></li>
              <li><a href="lab">Home(Lab)</a></li>
              <li><a href="radiology">Home(Radiology)</a></li>
              <li><a href="pharmacist">Home(Pharmacist)</a></li>
              <li><a href="cashier">Home(Cashier)</a></li>
              <!-- <li class="nav-header"></li> -->
              <li><a href="/patient/default/manage_patients">Patients</a></li>
              <li><a href="tasks">Task Lists</a></li>
              <li><a href="appointment">Appointment</a></li>
              <li><a href="order">Order</a></li>
              <li><a href="consumables">Consumables</a></li>
              <li><a href="prescriptions">Prescriptions</a></li>
              <li><a href="immunization">Immunization</a></li>
              <li><a href="laborders">Laboratory Orders</a></li>
              <li><a href="radiologyorders">Radiology Orders</a></li>
              <li><a href="patientaccounting">Patient Accounting</a></li>
              <li><a href=URL('admin','default','index'),>Admin</a></li>

{{end}}


<h1>Register Patient</h1>

{{=form}}

<script>
jQuery(document).ready(function(){
   jQuery('#no_table_mothers_name__row').hide();
   jQuery('#is_newborn').change(function(){
        if(jQuery('#is_newborn').attr('checked'))
            jQuery('#no_table_mothers_name__row').show();
        else jQuery('#no_table_mothers_name__row').hide();});
});
</script>


And this is the info from the page source showing the id's for what fields I am working with:

<tr id="no_table_is_newborn__row"><td class="w2p_fl"><label for="no_table_is_newborn" id="no_table_is_newborn__label">Is Newborn: </label></td><td class="w2p_fw"><input class="boolean" id="no_table_is_newborn" name="is_newborn" type="checkbox" value="on" /></td><td class="w2p_fc"></td></tr><tr id="no_table_mothers_name__row"><td class="w2p_fl"><label for="no_table_mothers_name" id="no_table_mothers_name__label">Mothers Name: </label></td><td class="w2p_fw"><input class="string" id="no_table_mothers_name" name="mothers_name" type="text" value=""

I think I have the right code for the jquery but nothing happens when I try this.

Any ideas?

Jim S

unread,
Jun 27, 2013, 12:11:21 AM6/27/13
to web...@googlegroups.com
Try this, you need brackets for your if statements in javascript.

jQuery(document).ready(function(){
 jQuery
('#no_table_mothers_name__row').hide();
 jQuery
('#is_newborn').change(function(){
   
if(jQuery('#is_newborn').attr('checked')) {
     jQuery
('#no_table_mothers_name__row').show();
   
} else {
     jQuery
('#no_table_mothers_name__row').hide();
 
 });
 
});
});

Tom Russell

unread,
Jun 27, 2013, 10:53:37 AM6/27/13
to web...@googlegroups.com
Thats weird, now it will not hide the the field but has no effect either when you check the checkbox.


--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jim Steil

unread,
Jun 27, 2013, 10:58:41 AM6/27/13
to web...@googlegroups.com
I'd try putting some alert() messages in to try to trace the flow and check the values of variables.



--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/FMaghI7MeTQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Tom Russell

unread,
Jun 27, 2013, 11:00:17 AM6/27/13
to web...@googlegroups.com
k thanks I will try that

Tom Russell

unread,
Jun 27, 2013, 11:26:56 AM6/27/13
to web...@googlegroups.com
So If I do something like:

jAlert('This is a custom alert box', 'Alert Dialog');

and nothing shows up, could it be that the jquery lib is not being made available?

Jim S

unread,
Jun 27, 2013, 3:31:06 PM6/27/13
to web...@googlegroups.com
Do you use firefox and firebug?

You can use the javascript console there to display to you any errors that might be occurring in your javascript.  You may have an issue earlier on in your page (with javascript) that is preventing the execution of your stuff later on.

-Jim

Tom Russell

unread,
Jun 27, 2013, 3:34:56 PM6/27/13
to web...@googlegroups.com
I use chrome but I will have to try that. Thanks.
Reply all
Reply to author
Forward
0 new messages