Solved

Assigning a PHP variable to an input id

Posted on 2011-03-16
8
438 Views
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,
Dean

 
<!DOCTYPE html>
<html lang="en">
<head>
	<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">
	<script>
	$(function() {
		$( "#datepicker" ).datepicker();
	});
	</script>
</head>
<body>

<div class="demo">

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

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



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

<?php

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


?>

</body>
</html>

Open in new window

0
Comment
Question by:deanlee17
8 Comments
 
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.
0
 
LVL 2

Expert Comment

by:sihar86
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.

0
 

Author Comment

by:deanlee17
ID: 35145859
Hi Dave,

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

Thanks,
Dean
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:deanlee17
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?

Thanks,
Dean.
0
 
LVL 2

Expert Comment

by:sihar86
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
0
 

Author Comment

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

Thanks.
0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 35146496
http://jqueryui.com/demos/datepicker/#option-dateFormat

Datepicker can have it's own custom format
0
 

Author Comment

by:deanlee17
ID: 35147427
Thanks roads.

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

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

0

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

839 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