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();
   });
 });
});


On Wednesday, June 26, 2013 9:09:00 PM UTC-5, Tom Russell wrote:
>
> 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?
>

-- 

--- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to