1

I use daterangepicker() to get two dates ( begginning and ending ), I'd like to put those dates in php variables.. i've succeeded to do an alert() to show those variables using a button.. but i don't know how to put them in the php. here's my code if anyone have an idea..


<script type="text/javascript">

$(function(){
    $('#rangeBa, #rangeBb').daterangepicker();
 });
function test(){
    var dates = new Array();
    dates[0] = document.inputdate.rangeBa.value;
    dates[1] = document.inputdate.rangeBb.value;
    return dates; 
}

</script>

<body>
    <form name="inputdate" method="post">
        <input type="text" value="m/jj/aaaa" id="rangeBa" name="rangeBa"/>
        <input type="text" value="m/jj/aaaa" id="rangeBb" name="rangeBb"/>
    </form>
    <button onclick="alert(test())">Click on this button</button>

</body>
Kirk ERW
  • 167
  • 1
  • 2
  • 14
  • They would be in the $_POST array if you submitted them to PHP just as they would in a normal form operation. – Jay Blanchard May 16 '13 at 14:27
  • 1
    you can do this by ajax if you want to set without reloading the page .. check this http://stackoverflow.com/questions/5004233/jquery-ajax-post-example/14217926#14217926 else you can set by normal form operation – NullPoiиteя May 16 '13 at 14:27

2 Answers2

6

You have to add a submit input element in your form and add an action parameter in your form:

<form name="inputdate" method="post" action="yourfile.php">
    <input type="text" value="m/jj/aaaa" id="rangeBa" name="rangeBa"/>
    <input type="text" value="m/jj/aaaa" id="rangeBb" name="rangeBb"/>
    <input type="submit" value="Click to send" />
</form>

And in yourfile.php: you get the variables by $_POST['rangeBa'] and $_POST['rangeBb']

Feel free then to use ajax method if you don't want a refresh of the page.

antoox
  • 1,309
  • 11
  • 9
2

After you submit your form you can find the form variables by name in $_POST. for example $_POST['rangeBa']

NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143