> $('#post_submit').attr('disabled', 'disabled'); > $('#post_form').keyup( function () { > if ($('#post_name', '#post_form').val() == '' && $('#post_content', > '#post_form').text() == '') $('#post_submit').attr('disabled', 'disabled'); > else ($('#post_submit', '#post_form').removeAttr('disabled')); > });
I think this would work. The "disabled" attribute can be set to a true/ false value in script. Since keyup can be an expensive thing, I just attached handlers to the two fields you needed to monitor rather than the whole form; you could attach it to the form if you prefer. Rather than set the initial value, I just triggered the handler to do its thing on the initial form values. I wasn't sure why you used .text() instead of .val() for the textarea, is there some kind of bug in .val() for textarea? Also, remember that any post content (even a bunch of spaces) will pass this test. You might want to do a bit more validation on the input if it's important to the page. $('#post_name, #post_content').keyup( function () { $('#post_submit').attr('disabled', !$('#post_name').val() || !$ ('#post_content').val() ); }).trigger("keyup");