0

I have 2 date pickers for Start date and End date... Could someone tell me why this does not POST anything to the DIV...

$(function () {
    var start1 = $('#start1');
    var end1 = $('#end1');

    start1.datepicker({
        onClose: clearEndDate
    });
    end1.datepicker({
        beforeShow: setMinDateForEndDate
    });

    function setMinDateForEndDate() {
        var d = start1.datepicker('getDate');
        if (d) return {
            minDate: d
        }
    }

    function clearEndDate(dateText, inst) {
        end1.val('');
    }
    $(function get() {
        $('#start1').daterangepicker({
            onSelect: function (dateText, inst) {
                $.post("report.php", {
                    dt_start: dateText
                }, function (data) {
                    $("#genreport").html(data);
                });
            }
        });
        $('#end1').daterangepicker({
            onSelect: function (dateText, inst) {
                $.post("report.php", {
                    dt_end: dateText
                }, function (data) {
                    $("#genreport").html(data);
                });
            }
        });
    });
});

The Datepickers open and I can select a date. The date shows in the box, but it does not GET or "post" anything to the DIV tag... I get nothing.

Thank you

Alan

Yi Jiang
  • 49,435
  • 16
  • 136
  • 136
Alan
  • 11
  • 1
  • It should "POST" to report.php, and update your div w/ id="genreport" with the response. I think you'll need to share the HTML to get a meaninful response here (unless there is superficial syntax error I don't see). Can you share? – jon_darkstar Nov 14 '10 at 09:43
  • Here is the Form that calls the datepickers.....

    Start Date: End Date:

    – Alan Nov 14 '10 at 09:51
  • Though I can't tell you a fix, I can suggest some debugging. Alerts in the callbacks and right before each $.post, a superficial echo in your report.php to see if its output gets displayed in div "genreport" at all. One idea -- is the datePicker a single element or several disjoint elements for each component (day, month, year). If there are several, you should bind that function to onchange for the whole class of them – jon_darkstar Nov 14 '10 at 09:51
  • Here is the DIV Tag....
    – Alan Nov 14 '10 at 09:51
  • what kind of input does "report.php" expect? Date object? String? unix_timestamp? [day, mon, year] array? This is real tough to crack without seeing the pieces – jon_darkstar Nov 14 '10 at 09:56
  • this could help, as it seems you are defining part of the prototype twice where once would be sufficient with a $(this) kind of thing to distinguish which one. http://stackoverflow.com/questions/887696/jquery-datepicker-onselect-wont-work – jon_darkstar Nov 14 '10 at 10:02
  • I can't get anything from the report.php. At this moment, I only have "good afternoon" written in the report.php file... It should echo that to the genreport DIV once I select (onSelect) the dates in the datepicker... right ??? WHat I have in MySQL is a simple table with Date, Time, Power, Volt, Current and I want to select a date range from the datepickers to create a "report" in the date range selected... My SOlar Panel inverter is connected to the MySQL Table, and data is input every hour (24 hours a day). I want to see this on the website I made, then I can print out the information to – Alan Nov 14 '10 at 10:13

2 Answers2

0

you are creating both datepickers twice:

start1.datepicker({
    onClose: clearEndDate
});

and then:

$('#start1').daterangepicker({

check it with firebug here: http://jsfiddle.net/KF9hb/12/

fazo
  • 1,807
  • 12
  • 15
  • Hmmmm... it still only shows the Start and End datepicker there as well... Not 2 of both – Alan Nov 14 '10 at 09:57
  • "Not 2 of both" what do you mean? – fazo Nov 14 '10 at 10:02
  • not twice in the HTML sense, but the javascript sense. See the SO link in my last comment! Also -- what is with "get()" ?? It clearly is not related to the ajax get, is it something to do with the DOM get? Or did you just decide to call your own function get()? If its the latter, that function does NOT need to be named. – jon_darkstar Nov 14 '10 at 10:05
  • i didn't put "get" there. i didn't even refer to it – fazo Nov 14 '10 at 10:13
  • I can see what you are talking about. the start of the script is to make the end datepicker only pick future days of the satert datepicker, and then if they click in the start datepicker, it will clear the end datepicker to basically start a clean slate, then the last part is the GET and POST to call the information with PHP and the data in MySQL. I am having one hard time here... – Alan Nov 14 '10 at 10:23
0

Fazo (in his answer) and I (in last comment with link jQuery datepicker, onSelect won't work) are suggesting the following.

    $('#start1').daterangepicker({
        onSelect: function (dateText, inst) {
            $.post("report.php", {
                dt_start: dateText
            }, function (data) {
                $("#genreport").html(data);
            });
        }

        onClose: clearEndDate

    });

rather than the two seperate places where you put start1.datepicker and $('#start1').datepicker, and similarly for end1

Community
  • 1
  • 1
jon_darkstar
  • 16,398
  • 7
  • 29
  • 37
  • I am trying to 1- have the start and end date as a range to select data from MySQL table, and 2- the end date must be greater (future date) then the start. These 2 things are messing me up... – Alan Nov 14 '10 at 10:41
  • thats fine. im guessing report.php accesses the database and setMinForEndDate ensures that end date as after start date? (or at least that this is the intention). I don't see anything wrong with those aspects, its the double-initialization thing thats messing you up. Try what Fazo and I suggest, and do some routine debugging like I described in comments. – jon_darkstar Nov 14 '10 at 14:55