Get value from ajax-loaded form before submitting

Posted by ldvldv on Stack Overflow See other posts from Stack Overflow or by ldvldv
Published on 2010-12-26T13:50:41Z Indexed on 2010/12/26 13:53 UTC
Read the original article Hit count: 225

Filed under:

Hi,

I have an app that loads an ajax form when a button is clicked. I then want to check a value in that ajax loaded form called "comment_content" so that I don't send an ajax request if the comment_content is empty. I can capture the form submission using the live method, however, I can't capture the form element because it needs an element.

I was looking at livequery but was wondering if there is a more efficient way by using live or if that I shouldn't even bother? Your help is very much appreciated.

    $("#comment_submit").live('click', function(){
       var comment = $("#comment_content").html();
       if(comment == ""){
          $("#notice").html("").stop(true, true);
       $("#notice").append("<p>Are you going to write something in that comment?</p>");
       $('#notice').slideDown().delay(2000).slideUp();
       return false;
       }
   return true;
});

© Stack Overflow or respective owner

Related posts about jquery-ajax