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>
2
  • They would be in the $_POST array if you submitted them to PHP just as they would in a normal form operation. Commented May 16, 2013 at 14:27
  • 1
    you can do this by ajax if you want to set without reloading the page .. check this stackoverflow.com/questions/5004233/jquery-ajax-post-example/… else you can set by normal form operation Commented May 16, 2013 at 14:27

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.