Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Assigning a PHP variable to an input id

Posted on 2011-03-16
8
Medium Priority
?
446 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
[X]
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
8 Comments
 
LVL 84

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
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…
Suggested Courses

604 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