Web Design with HTML and CSS

(National Geographic (Little) Kids) #1

214


Interactivity on the web

Web Design with HTML and CSS Digital Classroom

3 Preview the page, and then click the Submit button. Nothing happens, except for the
default behavior of the button, which is a non-functional element on your web page.

HTML cannot validate whether a form fi eld was fi lled out; you need JavaScript for this functionality.

You need JavaScript to make this button interactive, since HTML lets you perform
activities such as control the text that appears on the button, but off ers no interactivity
control. You will add JavaScript code to trigger a window to appear in your browser
and prompt you to type your name. When you type your name and click OK, your
JavaScript code will write your name on the page.
4 Below the <title> tag in your page, type the following code:
<script type="text/javascript">

</script>
You need to indicate in your HTML that you want to use JavaScript, just as you do with
CSS. You can place these instructions anywhere in the HTML code, but best practice is
to add them to the <head> section of your page.
Free download pdf