Solved

Assigning a PHP variable to an input id

Posted on 2011-03-16
8
435 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 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
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
Comment Utility
Hi Dave,

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

Thanks,
Dean
0
 

Author Comment

by:deanlee17
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 2

Expert Comment

by:sihar86
Comment Utility
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
Comment Utility
Dont worry, i think ive sorted it :)

Thanks.
0
 
LVL 27

Accepted Solution

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

Datepicker can have it's own custom format
0
 

Author Comment

by:deanlee17
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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 dynamically set the form action using jQuery.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now