jquery hide feild

Associate
Joined
19 Jul 2006
Posts
1,847
Just a bit stuck, I have this
Code:
$(function () {
            $('.dueDate').hide();
            $('#Pregnant').change(function () {
                if ($('#Pregnant').is(':checked')) {
                    $('.dueDate').show();
                } else {
                    $('.dueDate').hide();
                }
            });
}
So Basically in my form I the due date is hidden until the is pregnant box is ticked. This works fine on the create form view.
But in the edit form view i have a problem as that code works as it should. but not how i want it to.

If on the create form the pregnant box is ticked and the due date is filled in. On the edit page when the form loads the pregnant box is ticked but the due date is hided, until I click the pregnant box twice.

Im new to jquery functions
 
Associate
OP
Joined
19 Jul 2006
Posts
1,847
I have set up a cut down JSFiddle http://jsfiddle.net/Cs77M/ this works and i can keep repeating this
Code:
if (!$('#Pregnant').is(':checked'))
                $('.dueDate').hide();
            $('#Pregnant').change(function () {
                if ($('#Pregnant').is(':checked')) {
                    $('.dueDate').show();
                } else {
                    $('#DueDate').val('');
                    $('.dueDate').hide();
                }
            });
and change the id and class selectors for stuff is there a way to turn this into a function that I can pass variables to

eg
var thingtoselect1
var thingtoselect2

var thingtohide1
var thingtohide2

does that make sense. Im happy doing it the way i have it but I dont think its the best way WET
 
Back
Top Bottom