Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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($) {
    $('#update-form').submit(function(){
        data = {
            action: 'update_beginning_balance'
        };
        $.post(ajaxurl, data, function(updatebbal) {
            $('#updated-bbal-result').html(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.

Thanks

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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 */
  die(1);
}
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.

share|improve this answer
    
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 '13 at 6:51
    
That's fine, if that doesn't works provide me a link or better details. –  sven May 6 '13 at 6:55
    
Hello, I have a very long reply, so I paste it here pastebin.com/QeKDwhw3 thanks –  bagwis May 6 '13 at 7:15
    
Thank you very much –  bagwis May 6 '13 at 7:18
    
Okay I will try that new code. Will response again if it will work. –  bagwis May 6 '13 at 7:21
show 7 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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