- Advanced menus (eg, drop–down menus, slide–out menus, etc).
- Client-side form validation. Ensures the user has completed a form correctly before it's submitted to the server.
- Setting cookies. This could assist in your website "remembering" its users' preferences, or which pages they viewed during their last visit, etc.
- And much more…
onclick event handler content attribute, like this:
<script> tags, it will run (as long as it doesn't have any bugs!).
onclick event handler).
<head> and call that function from within the HTML code.
Event Handler Content Attributes
Client-Side vs Server-Side
Client-side scripts tend to feel much quicker and more responsive than server-side scripts. This is because there's no need to call the server like a server-side script would need to do. The client-side script runs in the browser and the browser responds instantly. Calling a server-side script usually feels slower (even if the server-side script runs blisteringly fast on the server) because of the latency between the client and the server—the user's request must travel across the internet to the server, then once the script has run on the server, the result must travel back across the internet to the user. Although this may only take a second or so, a second can feel like a long time—especially when client-side scripts will usually respond within milliseconds.
Despite the benefits of client-side scripting, server-side scripting is an essential part of web development. Most modern websites will have a combination of client-side scripting and server-side scripting. Server-side scripts can process forms, query databases, implement security measures, and much more that you wouldn't (and/or couldn't) do on the client-side.
<script> element and event handler content attributes.