Forum Moderators: open

Message Too Old, No Replies

How to add number with PHP within Javascript?

         

toplisek

11:21 am on Dec 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



How to add number with PHP within function of Javascript like 2011?
<SCRIPT>
document.write("<font size=1>" + day + month);
document.write(myweekday + ", " + 2011 + "</font>");
</SCRIPT>

daveVk

2:01 am on Dec 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document.write(myweekday + ", " + 2011 + "</font>");
could be written as
document.write(myweekday + ", 2011 </font>");

but suspect that is not the question ?

Can your not set year in the same way you set day month myweekday ?

document.write(myweekday + ", " + year + "</font>");

SteveWh

10:40 am on Dec 9, 2010 (gmt 0)

10+ Year Member



Not entirely sure this answers your question, either, but here's a possibility. The PHP code is run at serve-time, so it inserts the number into the JavaScript code, which gets run later, when it reaches the visitor's browser:

<?php 
$nextyear = "2011";
?>

<SCRIPT>
document.write("<font size=1>" + day + month);
document.write(myweekday + ", <?php echo $nextyear; ?> </font>");
</SCRIPT>

[edited by: SteveWh at 10:46 am (utc) on Dec 9, 2010]

SteveWh

10:40 am on Dec 9, 2010 (gmt 0)

10+ Year Member



Deleted double-post.

toplisek

6:43 pm on Dec 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It does not detect 2012

daveVk

6:02 am on Dec 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Somewhere in the page there probably code like

<SCRIPT>
var day = ...;
var month = ...;
var myweekday = ...;
</SCRIPT>

to which you need to add

var year = ...;

I have no idea how the year (or other fields) are calculated ( the ... past ), if you can find and paste this code it would help.