how to check if input type date is empty or not using javascript or jquery -


i have following html form:

<form id="chartsform">     <div id="dateoptions">         <p>until date: <input type="date" name="until_date" value="until date"></p>         <p>since date: <input type="date" name="since_date" value="since date"></p>     </div>     <div class="insightsoptions">         <input id="newlikes" class="insightsbuttons" type="submit" name="submit" value="daily new likes">         <input id="unlikes" class="insightsbuttons" type="submit" name="submit" value="daily unlikes">     </div> </form> 

and following jquery script:

$(function () {     $("#newlikes").one('click', function () {         $.ajax({type:'get', url: 'newlikes.php', data:$('#chartsform').serialize(), success:             function(response) {                 alert(response);                 $("#dailynewlikes").html(response);             }});         return false;     });     $("#newlikes").on('click', function(){         $(this).toggleclass('green');         $('#dailynewlikes').toggle();     }); 

how check if inputs "until_date" , "since_date" empty or not in first place , if empty stop script before executes ajax call, alert user mistake , continue if inputs not empty anymore. have use .one(). i've tried .blur() function no effect...

instead of using one() remove handler upon success. if need 1 function removed afterwards either use namespaced events (or named function rather anonymous one). this:

$("#newlikes").on('click', function () {      var until = $('#dateoptions input[name="until_date"]').val();     var since = $('#dateoptions input[name="since_date"]').val();      if (until == "" || since == "") {         alert('error; until date or since date missing.');         return;     }      $.ajax({         type:'get',         url: 'newlikes.php',         data: $('#chartsform').serialize(),         success: function(response) {             $("#dailynewlikes").html(response);             $("#newlikes").off('click');         }     }); }); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -