Search code examples
jqueryajaxlive

prevent submit until input change


I have this little code to post via ajax:

$('#submit').click(function () {
    var myName = $('#name').val();
    var myContent = $('#content').val();

    // ajax
    $.ajax({
        type: 'post',
        url: '/ajax.process.php',
        data: {
            post_name: myName,
            post_content: myContent
        },
        dataType: 'json',
        success: function (data) {
        alert(OK);
        }
    }); // end ajax
});

How I can prevent or disable the .click until my inputs are changed, I mean until user make some modification?


Solution

  • You could replace submit with type="button" and use that ajax on users input change, like:

    //make input type="submit" to
    <input type="button".... />
    
    $("yourInputId").blur(function() {
      $.ajax({}); // use ur ajax here
    });