OK, first thing, and this applies to ALL
J2EE, not just JSF: When you have a Model/View/Controller architecture, you shouldn't be putting code in the View template. Doing so violates the Separation of Concerns aspect, and in more practical terms it makes the application a lot more expensive (and less fun) to support.
Aside from that, the whole "JSP" concept went out the window in JSF2, so all those
JSP elements and scriptlets lose support entirely. Scriptlets will get you yelled at even in our JSP forum, anyway. They were a hack until better things came along.
JavaScript runs on the Client. The backing beans are on the server. To make the twain meet, you need AJAX. You could roll your own AJAX from raw JavaScript, but if you value your sanity, I recommend using an AJAX support library such as jQuery. Many of the JSF extension frameworks use jQuery internally, as a matter of fact.