This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
the reason it worked here, is because i placed the script AFTER the form. So, the html code is being parsed by the browser, and THEN the script is parsed. So the browser knows about what the script is talking.
But, if the script is placed before that form (without the function() ) the script is parsed before the html is parsed. So it does not know about what it is talking.
now, the "$(function()" tells the browser to "parse" the script, after the page is loaded. So, wherever you put your script code with that "function", it will always work.
Actually, the best place for scripts, is always in the bottom of your page, to be sure they certainly work.