Getting selected date from calendar date picker

北慕城南 提交于 2019-12-13 04:06:25

问题


I need help with getting the selected date from calendar date picker. Currently I can select the date(from...to...) and place it into textbox. But I cannot get the value to put into PHP variable.

<head>


    <meta charset="utf-8" />
    <title>jQuery UI Datepicker - Select a Date Range</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />
    <script>
        $(function() {
            $( "#from" ).datepicker({
                defaultDate: "+1w",
                changeMonth: true,
                numberOfMonths: 3,
                onClose: function( selectedDate ) {
                    $( "#to" ).datepicker( "option", "minDate", selectedDate );
                }
            });
            $( "#to" ).datepicker({
                defaultDate: "+1w",
                changeMonth: true,
                numberOfMonths: 3,
                onClose: function( selectedDate ) {
                    $( "#from" ).datepicker( "option", "maxDate", selectedDate );
                }
            });


        });
    </script>
</head>
<body>


        <label for="from">From</label>
        <input type="text" id="from" name="from" />


        <label for="to">to</label>
        <input type="text" id="to" name="to" />

</body>

回答1:


You haven't got a form to submit. You should create a form first, like so:

<form action="foo.php" method="post">

    <label for="from">From</label>
    <input type="text" id="from" name="from" />


    <label for="to">to</label>
    <input type="text" id="to" name="to" />

    <input type="submit" value="Submit dates">
</form>

And on the server side, if you're submitting the form via POST (as in the example above), you can obtain the dates from the PHP $_POST variable:

$from = $_POST['from'];
$to = $_POST['to'];



回答2:


On submitting that form you can get that from that name of the input which you have pointed for the date. (i.e) $_POST['from'] and $_POST['to'].




回答3:


To retrieve the value in PHP you can do it by two way. 1> Either by placing form and a submit button and get those value in POST. 2> Second one is by AJAX call in blur events of the input box.



来源:https://stackoverflow.com/questions/16956413/getting-selected-date-from-calendar-date-picker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!