views:

38

answers:

1

I am attempting to use jquery to validate a date that is broken up into MM DD YYYY fields.

<form name="dateform" id="dateform">
<input type="text" name="month"/>
<input type="text" name="day"/>
<input type="text" name="year"/>
</form>

I can only find examples that use a single field, which is not what I want.

<form name="dateform" id="dateform">
<input type="text" name="date"/>
</form>

Any examples I can follow?

A: 

You might try assembling your individual fields into a javascript date object.

var $form = $('form#dateform');
var dateToCheck = new Date( 
   $form.find('input[name=year]').val(), 
   $form.find('input[name=month]').val(),
   $form.find('input[name=day]').val() );

Then apply whatever validation you need to dateToCheck. If you'd like to use the validate plugin, one approach would be to store/update the assembled full date in a hidden field, and validate that field.

Ken Redler