jQuery Form Plugin & jQuery DatePicker Not Working Together
I'm trying to use jQuery's Form Plugin. I'm using the JSON example here.
For some reason the datepickers are not showing on the page, when I use the jQuery Form Plugin. In my jquery file I've got:
jQuery.noConflict();
jQuery(document).ready(function($) {
$('#csf_map_form').ajaxForm(function() {
dataType: 'json',
success: process_json
});
function process_json(data) {
alert(data.csf_map_offense_group1);
}
$('#csf_map_start_date').datepicker({
dateFormat : 'mm/dd/yy',
yearRange : '2011:2011',
changeMonth: true,
changeYear: true,
defaultDate : new Date(2011, 8-1,1),
minDate : new Date(2011, 1-1,1),
maxDate : new Date(2011, 8-1, 25)
});
$('#csf_map_end_date').datepicker({
dateFormat : 'mm/dd/yy',
yearRange : '2011:2011',
changeMonth: true,
changeYear: true,
defaultDate : new Date(2011, 8-1, 25),
minDate : new Date(2011, 1-1,1),
maxDate : new Date(2011, 8-1, 25)
});
});
In my php file, the form looks like:
//start form
$output .= '<form id="csf_map_form" action="path-to-file/csf_map_form_handler.php" method="post" >';
//1st datepicker
$output .= '<div>';
$output .= '<label for="csf_map_start_date">Start Date:</label>';
$output .= '<div id="csf_map_start_date" style="font-size: 10px;"></div>';
$output .= '</div>';
//2nd datepicker
$output .= '<div>';
$output .= '<label for="csf_map_end_date">End Date:</label>';
$ou开发者_高级运维tput .= '<div id="csf_map_end_date" style="font-size: 10px;"></div>';
$output .= '</div>';
//radio button group div
$output .= '<div style="float: left; width: 150px; margin: auto; padding-left: 20px; ">';
$output .= '<label for="csf_map_group1">Select Offense:</label><br />';
$output .= '<input type="radio" name="csf_map_group1" checked="checked" value="TINY">Tiny</input><br />';
$output .= '<input type="radio" name="csf_map_group1" value="MEDIUM"/>Medium</input><br />';
$output .= '<input type="radio" name="csf_map_group1" value="LARGE">Large</input><br />';
$output .= '</div>'; //end radiobuttons
$output .='<input type="submit" value="Submit" />';
$output .= '</form>';
For some reason the ajaxForm is conflicting with the datepicker. If I comment out the function starting $('csf_map_form').ajaxForm and the process_json function, then the datepickers in the form work fine. If I don't comment them out then the datepickers don't appear. But, the alert fires when submit is clicked. It alerts what was selected in the radiobutton.
Any ideas as to what is going on? How do I get them to play nice? What error am I making?
Thank you.
Hurray, I figured it out.
1) I changed the inline datepickers to the default-- replace the divs on the datepickers with .
2) I was missing the '#' in the $('#csf_map_form').
3) In the csf_map_form_handler.php, I was only returning only one part of the form's info. When I changed it, so that I returned the start and end dates and the radiobutton's selection, it worked.
Thank you.
精彩评论