0

I have a javascript code showing current time, which i want to store in php variable. The store value in php will then be used in sending through form to an email id. I just want to store the value in php.
document.getElementById('time')
Any Help/ideas appreciated.

<script type="text/javascript">
    <!--
    function updateTime() {
        var currentTime = new Date();
        var hours = currentTime.getHours();
        var minutes = currentTime.getMinutes();
        var seconds = currentTime.getSeconds();
        if (minutes < 10){
            minutes = "0" + minutes;
        }
        if (seconds < 10){
            seconds = "0" + seconds;
        }
        var v = hours + ":" + minutes + ":" + seconds + " ";
        if(hours > 11){
            v+="PM";
        } else {
            v+="AM"
        }
        setTimeout("updateTime()",1000);
        document.getElementById('time').innerHTML=v;
    }
    updateTime();
    //-->
</script>

Edited by sandeep.tete

7
Contributors
6
Replies
46
Views
4 Years
Discussion Span
Last Post by JorgeM
1

You can store the value in a hidden input field in the form which will then be picked up when form is submitted.

<input type="hidden" id="hidden-date" />

And in the javascript I guess you change line 21 to:

document.getElementById('hidden-date').value = document.getElementById('time').innerHTML;

Edited by broj1

0

You can't directly asign php varible values from javascript.
Php is server side script.
If you want this value for your form , use hidden input type and asign that value to this hiden input type.

0

If you are just trying to get the current date and time for your use in PHP use the date() function. Date - php.net.

If you are going to store in a database I suggest using the UNIX Timestamp, which you can call in your SQL call.

0

The answer is provided by broj1 in the second post of this thread. You can save the value in a input type hidden element within the form. Once the form is posted you can pick up the value in your php script like you would for any other input element.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.