Solved

Assigning a PHP variable to an input id

Posted on 2011-03-16
8
437 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

810 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