-2

I want to store the value of dates in a variable which user selects without using form.I am able to fetch date using javascript but for my application i need to store them in php variables.

 <html>
    <head>
    <script>
function myFunction() {
    var x = document.getElementById("date1").value;
    document.getElementById("demo").innerHTML = x;
    var y = document.getElementById("date2").value;
    document.getElementById("demo1").innerHTML = y;
}

    </script>
    </head>
    <body>
    <?php
            echo '<button onclick="myFunction()">Try it</button>';
            echo '<input type="date" name="date1" >';
            echo '&nbsp';
            echo '<label>'."Date2:".'</label>';
            echo '<input type="date" name="date1">';
            echo '<p id="demo"></p>';
            echo '<p id="demo1"></p>';  
    ?>
    </body>
    </html>
julianstark999
  • 3,450
  • 1
  • 27
  • 41
Aryan
  • 61
  • 9
  • You can put the values inside hidden fields which later you can retrieve while form submit. – Shrikant Mavlankar Aug 02 '16 at 13:42
  • You can't do this. Your php already rendered page, you can't use it anymore. If you want store values from user input you need to post form or use ajax request and handle it with your php script. – Maxx Aug 02 '16 at 13:42
  • why to you need to store them in php variables ? If you want to access it on server side you can use an ajax post request – Olivier Boissé Aug 02 '16 at 13:43
  • http://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript?rq=1 Check this link out... – martin Aug 02 '16 at 13:44
  • 2
    You can't "pass a variable" to a _language_. What you are describing is communication between _systems_, that happen to be implemented using different technologies, possibly on different computers. Now you have two lines of inquiry for your continued research. – Lightness Races in Orbit Aug 02 '16 at 13:47
  • Are you new to web development? It's a bit unclear but I think what you want is to get user input back to a script to the server. You say you don't want a form, but it really is the old-school, easiest way of doing it. You alternative is indeed to learn a bit of AJAX. Furthermore, I see you're using to output static unchanging HTML. That's not really necessary. You can just send the HTML directly without the ` – Ben Hillier Aug 02 '16 at 13:56

1 Answers1

0

you can use ajax to send the values that you what to a php and use get or post to take the values

I use ajax on jquery