Jump to content

Insert Java Script Date into PHP Echo Statement


yandoo

Recommended Posts

Hi all,

i was hoping for some technical help using php and mysql.

I have a simple database connected (mysql) and website (php/html).

A form of this website involves me inputting a date field in it. i have created a date function using the following javascript code:

var todaysdate = new Date();
year = todaysdate.getFullYear();
month = todaysdate.getMonth();
date = todaysdate.getDate();
day = todaysdate.getDay();

var monthname = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
var dayname = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");


The date is inserted into the webpage using the following code:

<script language="JavaScript" type="text/javascript">
document.writeln(year+"-"+monthname[month]+"-"+date);
</script>.

Basically i want to be able to insert this javascript date (by default) into the date field of my form, using the php echo method, if it is possible????


Example:
<?php echo <script language="JavaScript" type="text/javascript">
document.writeln(year+"-"+monthname[month]+"-"+date);
</script> ?>

Please help as this is doing my head in!!!!!

Thank You

tom
Its not possible to create something in Client side script and have Server side script return the value without first sending data to the server for the server side script to process it.

If there is an event trigger in Javascript similar to OnLoad, or OnOpen in VBA you might be able to set the default value of that HTML control to the date worked out by your script above when the user first opens the webpage, in this case you do not need PHP at all.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.