I want to send the date parameter to php but don't know how to do it
var date = new Date();
var day = date.getFullYear();
How do I echo the var day in php ?
I want to send the date parameter to php but don't know how to do it
var date = new Date();
var day = date.getFullYear();
How do I echo the var day in php ?
You need to create a function in PHP callable from Ajax. But there is no way for you to "see" the echo directly. Don't forget that PHP is executed on the SERVER side, and Javascript on the Client side. So they can't exchange information directly. Instead, you can get the HTML result of an ajax query. There is an exemple in the jquery documentation.
If you just want to echo javascript variable in php without ajax follow this
<script>
var date = new Date();
var day = date.getFullYear();
</script>
<?php echo "<script>document.write(day)</script>"; ?>
you can verify this code at http://phpfiddle.org/
Set value in this input box using the Javascript
<script>
var date = new Date();
var day = date.getFullYear();
document.getElementById("dateParam").value=day;
</script>
Here is the form
<form action="yourPHPfile" method="post">
<input type="text" id="dateParam" name="day"/>
<input type="submit">
</form>
When you will submit this you will get the data in as a parameter.
In your PHP file
if(isset($_POST['day'])){
echo $_POST['day'];
}
So you can try this.
You need to use Ajax
because php
is server side and javascript
is client side so there is only one way to send parameter to php
is Ajax, Ajax is a bridge of client to server-side.