Quote:
Originally Posted by darksniperx
when the code is inside an html it works. when the code is placed in external js file, it wont work, it just prints <?php print date('Y'); ?> instead of the value it suppose to generate.
why???
|
It does that because an input field converts everything to text.
If you want to get it to output the current year you will have to
use Javascript instead of PHP.
A simple example:
And the contents of date.js:
date.js
Javascript Code:
var d = new Date();
var y = d.getYear();
document.getElementById("pub_year_id").value = y;
There are other options to using Javascript.
You could have a variable set to the current year using PHP
in an external file and then include() the file in your page.
Like this:
External date.php file:
date.php
Your page: