Who This Article is For
Detecting what type of browser a partcular user is visiting your site with. This helps ensure that the web page displays properly for that visitor.
Storing using information from a user. For instance, maybe you want to display a survey to a user, but only want to display it to them once. You can store a cookie on their computer so that the survey will not display when they visit again.
Validating data that is entered into a form. For instance, if a user tries to enter text into a phone number field, you can detect this and give a warning message.
Adding interactivity to a website. You can have "clickable" events that respond to a users actions, such as when they click on a particular HTML element.
Update page content or submit data without needing to refresh the page.
Create animations and transitions, such as having HTML elements increase/decrease in size, change color, fade in and out, move, and so forth.
One more thing to know before we test out some code - the <script></script> tags can be placed in either the <head> or <body> section of your HTML document, with the typical placement being in the <head> portion of your page.
Here is a simple way to display some text in the user's browser:
<p>This is text displayed in an HTML paragraph tag</p>
</script> </body> </html>
Next you will note the document.write function (we will discuss functions in more detail in a later article, but for now, think of them as mini programs). This particular function causes the data contained within (" "); to be displayed to the user's browser. If you pop this code into a .txt file, save the file with the extension .html, and double click on it, you should see a web page that displays the text:
This is text displayed in an HTML paragraph tag
A few more things before we move forward: