Ex 7 - disable the Post button so that empty messages can't be posted when the page loads


#1

Instructions say "Lastly, let's disable the Post button so that empty messages can't be posted when the page loads. " Why is this necessary since the $(document).ready(main); doesn't run until AFTER the page loads?

Thanks.


#2

@brosenrscinc.net Could you show your code? Maybe I can enlighten you on this topic.


#3

The code isn't the problem. It works. My question is why that single line of code, at the very end of the function, after the event handlers, is necessary at all. It's explained as being necessary so that no empty messages can be loaded while the page is loading. However, it's my understanding that
$(document).ready(main); won't run until after the page is loaded.

Thanks.


#4

(I hope you don't mind my jumping in here, @quobogeba)
@brosenrscinc.net -

Exactly - it's necessary so that nothing will happen as the page is loading. $(document).ready(); runs once the page has finished loading, so none of our JavaScript code will run until after the page is loaded.
Does that make sense?


#5

@brosenrscinc.net From my understanding, if the page hasn't loaded all the way, your forms could still work somewhat, because they are in the html file, rather than JS. Is that even relevant? I apologize in advance if I completely missed the point of your question.


#6

Hi zystvan,

Thanks for jumping in. When you say 'AS the page is loading', do you mean that, for example, part of the form is visible but the page hasn't yet completely loaded so that the user can hit the POST button while the message area is empty and, therefore, no .length verification could be done?


#7

@brosenrscinc.net

I wasn't really thinking of anything specific, but yes, pretty much that :slightly_smiling: