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>
-
They would be in the $_POST array if you submitted them to PHP just as they would in a normal form operation.Jay Blanchard– Jay Blanchard2013年05月16日 14:27:53 +00:00Commented May 16, 2013 at 14:27
-
1you 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 operationNullPoiиteя– NullPoiиteя2013年05月16日 14:27:54 +00:00Commented May 16, 2013 at 14:27
2 Answers 2
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.
Comments
After you submit your form you can find the form variables by name in $_POST. for example $_POST['rangeBa']