Reputation: 10961
I'm using jQuery
's datepicker
in other to get some dates from the user. I defined the form was following:
<form id="myform" action="/graphs/get_builds" method="post">
Start: <input type="text" id="start" />
End: <input type="text" id="end" />
<input type="submit" value="Go" />
</form>
on the JS
side, I have:
$(document).ready(function () {
var data = {
'start': $('#start').datepicker({
onSelect: function(dateText, instance) {
return $(this).datepicker('getDate');
}
});
};
console.log(data);
// bind 'myform' and provide a simple callback function
$('#myform').ajaxForm(function () {
console.log("Hello");
});
});
I know the definition on the data
value it's not right, but how could I get the value of start
and end
in other to pass that to a back to the ajaxForm
. I need the value of both start
and end
. On the server side I have a method waiting for both the start
and end
dates so I could perform some operations. How could I accomplish that?
Upvotes: 0
Views: 58
Reputation: 289
The "start" and "end" are already in the form. All you have to do is submit it to the server via ajaxSubmit.
var options = {
target: '/graphs/get_builds' // the target server side page
};
$('#myform').submit(function() {
// submit the form via ajax
$(this).ajaxSubmit(options);
return false;
});
Upvotes: 0
Reputation: 1922
Use the input value (set by datepicker). To get by server side you need to set 'name' property first.
$('#myform').ajaxForm( function() {
var start_data = $("#start").val();
var end_data = $("#end").val();
console.log(start_data);
console.log(end_data);
console.log("Hello");
});
Upvotes: 1