Assigning a PHP variable to an input id

Posted on 2011-03-16
Last Modified: 2012-06-27
Hi Experts,

Im currently trying to build a date picker. I have it working, however it diaplays the date in the following format 03/19/2011. I need this to be 19-03-2011

To change this I was first going to replace the "/" with "-" using...

$datepicker = str_replace("/","-",($datepicker));

and then apply...

$Arrival_Date = date("d-m-Y", strtotime($Arrival_Date));

But how do i get the form id into a variable called $datepicker if I change the input ID name to $datepicker the data picker stops working all together.

Many Thanks,

<!DOCTYPE html>
<html lang="en">
	<meta charset="utf-8">
	<title>jQuery UI Datepicker - Default functionality</title>
	<link rel="stylesheet" href="jquery-ui-1.7.2.custom.css">
	<script src="includes/jquery-1.4.4.js"></script>
	<script src="includes/jquery.ui.core.js"></script>
	<script src="includes/jquery.ui.widget.js"></script>
	<script src="includes/jquery.ui.datepicker.js"></script>
	<link rel="stylesheet" href="newstyle.css">
	$(function() {
		$( "#datepicker" ).datepicker();

<div class="demo">

<p>Date: <input type="text" id="datepicker"></p>

</div><!-- End demo -->

<div class="demo-description">
</div><!-- End demo-description -->


$datepicker = date("d-m-Y", strtotime($datepicker));



Open in new window

Question by:deanlee17
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 83

Expert Comment

by:Dave Baldwin
ID: 35145800
You're trying to mix PHP and javscript in a way that can't work.  There is no PHP in your datepicker code, it's all javascript and jquery.  You need to alter the code in <script src="includes/jquery.ui.datepicker.js"></script>.  The PHP code is run before the page is sent to the browser and the javascript/jquery runs after it is received in the browser.

Expert Comment

ID: 35145832
agree with DaveBaldwin
alternative way beside alter jquery code (I think need not little effort to change that),
let it like mm/dd/yyyy format and change to dd-mm-yyyy when it output the report.


Author Comment

ID: 35145859
Hi Dave,

Thanks for the reply. So im guessing it is possible in javascript to reverse the dates around?

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.


Author Comment

ID: 35145869
Hi sihar86,

Maybe you're right, it needs to be formatted when its output from the database.

On that note ive just had a thought. How can i actually insert the date into the database if i cannot set the input ID to a PHP variable?


Expert Comment

ID: 35146094
How can i actually insert the date into the database if i cannot set the input ID to a PHP variable?
>>> the last statement seems not clear to me

Author Comment

ID: 35146151
Dont worry, i think ive sorted it :)

LVL 27

Accepted Solution

Lukasz Chmielewski earned 500 total points
ID: 35146496

Datepicker can have it's own custom format

Author Comment

ID: 35147427
Thanks roads.

Incase anyone else needs it the javascript should look like this....

$(function() {
$("#datepicker").datepicker({dateFormat: 'dd-mm-yy'});


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question