Skip to content Skip to sidebar Skip to footer

Pass Selected Date Values From Datepicker To Php

I found similar questions on here but most of the solutions don't work for me. I have a form with a datepicker and I want to pass the selected date to my php file but it doesn't se

Solution 1:

Since it seems you're doing nothing with the date after the onSelect has fired, the only thing wrong I see is that your input is lacking the name attribute, and it won't be visible in the $_GET superglobal

Change your input to something like:

<inputtype="text"id="mydate" name="mydate"/>

And it should work.

If you plan to store your date and time in a MySQL database, you could do something like this. First in your form:

<form name="myForm" action="createevent.php" onsubmit="return validateForm()" method="get"> 
<p>Date<input type="text"id="mydate" name="mydate"/></p>
<p>Time<input type="text"id="mytime" name="mytime"/></p>
<input type="hidden"id="mydatetime" name="mydatetime"/>
<input type="submit" name="submit" value="Submit" />
</form>

Then, in your validateForm() function, I would add something like this:

var date = $('#mydate').val(),
    time = $('#mytime').val();

var datetime = [date.replace('/','-'),time].join(' '); // 01-01-2013 01:21
$('#mydatetime').val(datetime);

Solution 2:

I didn't tried but I'm wondering maybe it's just your control got "name" missing, try change it as following:

<inputtype="text"id="mydate" name="mydate"/>

Solution 3:

Made change in input box

<inputtype="text"id="mydate" />

TO :

<inputtype="text"id="mydate" name="mydate"/>

When you will submit form it will submit name value of textbox mydate and you can get it by $_GET["mydate"]

Post a Comment for "Pass Selected Date Values From Datepicker To Php"