JQuery check two input boxes before send ajax

Discussion in 'Programming' started by bumbar, Feb 13, 2011.

  1. #1
    Hi!
    I have a form with 2 fields datepicker. How do I check both boxes have a date before I send ajax data?

    Here is my code. It examines only one data field...

    
    (document).ready(function(){
    
    $('#datepicker, #datepicker2').change(function () {
    
       var datepicker     = $('#datepicker').attr('value');
       var datepicker2     = $('#datepicker2').attr('value');
    		$.ajax({
    			type: "POST",
    			url: "test/ajax",
    			data: "datepicker="+ datepicker +"& datepicker2="+ datepicker2,
    			success: function(){}
    		});
    
    });
    
    PHP:
    form with two input tags
    
    <form id='submit' action="/frontend_dev.php/availability" method="POST">
    <input class="text" id="datepicker" type="text" name="CheckIn" />
    <input class="text" id="datepicker2" type="text" name="CheckOut" />
    </form>
    
    PHP:
    The code only checks one of the two fields and sends the data. Pfu. :mad:
     
    bumbar, Feb 13, 2011 IP
  2. ipr22

    ipr22 Peon

    Messages:
    113
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    just use a simple if statement to check the values of the two datepicker variables before firing off the ajax request
     
    ipr22, Feb 13, 2011 IP