How to pass the jquery datepicker value in form POST method?

I have a input text in the form for date and i use JQuery datepicker to select date.

 <input type="text" id="datepicker" name="datepicker" value="Date"/>

when i use form post to post the values into another php for calculation. i don’t get the values from this input text alone. i get an empty value instead of selected date.

 $date=$_POST['datepicker'];

i’m not sure of how to pass the datepicker value in form POST. Can someone help me out?

Jquery datepicker value on Controller action method

I’ve created a extension method of Jquery datepicker, below are the source code. public static string DatePicker(this HtmlHelper htmlHelper, string name, DateTime? value) { if (!string.IsNullOrEmpty(n



How to pass in event data for jQuery datepicker events

I am trying to pass event data to a jQuery datepicker event handler, for ‘dataID’: input.datepicker({ onClose: function() { var datePicker = jQuery(this); customFunction(datePicker, dataID); } }); D

pass form data via jquery post

I have a form and what i need to do is to pass this form data to another page via jquery .post and below you will find the javascript <script type=text/javascript> $(form).submit(function()

How to pass ID value from Jquery DatePicker editable

This calender picker allows me to log the date value picked, but I need to pass the ID value in the tags as well, but I can’t get it to work. PLEASE HELP!!! Here is where we show the date value, and t

pass header value in jQuery AJAX POST firefox

I called a Rest service in jQuery AJAX POST method. I need to pass two values in header. Firefox neither pass the header value to the service nor calls the REST service. My Jquery code var postCall =

jQuery datepicker: Button disable unless both datepicker input fields have selected value

I am using jQuery datepicker, I have two datepicker input fields, like following: <html> <body> <form method=post> <input type=text id=’start_date’> //datepicker field <inpu

How to pass form data using POST method and JS submit()?

How to pass form data using POST method and JS submit() ? I would like not to use AJAX. I can achieve that by using JS and GET method, but my goal now is to use JS (probably with submit() ) and POST m

How to pass a g:datePicker value through a remoteFunction?

I tried to pass a g:datePicker value through a remoteFunction.But it return a null value.Anyone knows how to solve this problem? My GSP page: <%@ page contentType=text/html;charset=ISO-8859-1 %&g

Pass form object value to static method

I need to take a form object value and pass it into a static method: public void SetCalendarStartSafe(DateTime startDateSafe) { startDateSafe = calendarStart.Value; } private static DataTable GetData

How to resize jQuery datepicker?

I have jQuery Datepicker inside my form. My problem is after I have clicked inside textfield, datepicker shows too big. How can I resize datepicker?

Answers

jQuery’s datepicker has nothing to do with posting your form. If your form is set to “post” then whatever is left in that input field after the user has selected a date will be sent with the form.

<form action="process.php" method="post"> 
  <input type="text" id="datepicker" name="datepicker" value="Date"/>
</form>

Gives you:

$date = $_POST['datepicker'];

However if your form is being sent as a “get” request you’ll need to access it as such.

<form action="process.php" method="get"> 
  <input type="text" id="datepicker" name="datepicker" value="Date"/>
</form>

Gives you:

$date = $_GET['datepicker'];

That’s a simple form with a datepicker

   <form id="myform" name="myform">
    <input type="text" id="datepicker" name="datepicker" value="Date"/>
    <input type="button" id="submitMe">
    </form>

Now your jquery,we are going to use some AJAX stuff:

//init datepicker
$(function() {
    $("#datepicker").datepicker({
        showButtonPanel: true
    });
});

//pass deatepicker to php
$("#submitMe").click(function() {
    $.ajax({
        type: 'POST',
        url: "pass.php",
        dataType: "json",
        data: $('#myform').serialize(),
        success: function(data) {
            console.log("Done");

        }
    });
 return false;
});‚Äč

And finally your pass.php file

<?php 
//note that date may have slashes or dots so we url decode it

$date = urldecode ($_GET['datepicker']);

echo "chosen date is: ".$date;
?>
$( "#currentDate" ).datepicker("setDate", new Date("<?php echo $_POST['myCurrentDate'] ?>"));

works for me, read at least 10 very complicated ways of doing it and then realised this works. You are instantiating a new value each time. you store the date somewhere in your php scripts, using form input or some other technique and then recycle it back into the above statement. So reloading doesn’t affect the result.

If myCurrentDate is unset it will set it by default. Getting it to be set to today’s date requires a php if statement to set it the first time (or reload the page) to new Date() and the else statement can be used to include the above code.