I am new to ajax and I've been struggling for 3 days now on how to solve my problem. I am trying to fetch the value of the date input (input type="date" in html)and pass (post method) it to ajax so that it can be processed. My goal is to be able to update a certain post meta value of multiple posts filtered via post date in a specific date range selected by user using an html 5 date input.

Currently I only have a button which updates all the post meta value but the date range must be manually entered into the code, I couldn't make it possible to be dynamic where a user can select a date range like update post meta values of posts between April 1, 2013 and May 1, 2013.

My working ajax which can run my function is

jQuery(document).ready(function($) {
        data = {
            action: 'update_beginning_balance'
        $.post(ajaxurl, data, function(updatebbal) {
        return false;

I tried to use $(#id).val which I referred from here http://api.jquery.com/val/. I hope you could give me some ideas on how to $_POST my input date fields via ajax.

Or do you have any idea on how can I accomplish this task without using ajax? I am better with PHP compared to AJAX/JavScript.


1 Answer 1


If you want to post the value as soon as user has entered the date and click somewhere else, this might help you:

 jQuery('#your-name').on('blur', function(){
   var date_Value = this.value;
   var ajaxdata = {
        action: 'process_date',
        date_value: date_Value
   jQuery.post(ajaxurl, ajaxdata, function(res){ 
      /* whatever you want to do, res contains the output generated by your php file*/  

As you are using admin ajax, make a function to process this data.

function process_Date(){
  $date = $_POST['date_value'];
  /* do whatever you want to do with your $date*/
 /* return an output */
add_action('wp_ajax_process_date', 'process_Date');
add_action('wp_ajax_nopriv_process_date', 'process_Date');

Add this function to your file where you are having other functions.

  • Hello dot1, thanks for that, I will try it out first and will provide a feedback on what will be the result. Thanks again regards!
    – bagwis
    May 6, 2013 at 6:51
  • That's fine, if that doesn't works provide me a link or better details.
    – Kumar
    May 6, 2013 at 6:55
  • Hello, I have a very long reply, so I paste it here pastebin.com/QeKDwhw3 thanks
    – bagwis
    May 6, 2013 at 7:15
  • Okay I will try that new code. Will response again if it will work.
    – bagwis
    May 6, 2013 at 7:21
  • I used this pastebin.com/uvPLCuPd but I can't see any feedback. ajaxurl points to the wordpress' WP-Admin/admin-ajax.php. Thanks
    – bagwis
    May 6, 2013 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.