XHTML » Tags » script

Syntax:
<script> ... </script>

The script tag is used to place script code inside the head and body elements of an HTML code document. For all practical purposes, this tag is primarily used to allow the execution of JavaScript code inside HTML code (and, to a lesser extent, VBScript).

The separate closing tag is mandatory.
 

Examples

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>DevGuru JavaScript Example</title>
<script type="text/javascript">
<!--
function checksubmit()
{
   if (document.formname.firstname.value == "")
   {
      alert("Please enter your full name")
      document.formname.firstname.focus()
      return false
   }
   if (document.formname.lastname.value == "")
   {
      alert("Please enter your email address")
      document.formname.lastname.focus()
      return false
   }
   return true
)
-->
</script>
</head>
<body>
... form goes here ...
</body>
</html>
Output:
If you wish to receive information about upgrades to dgCharge, please fill out this form.
Full Name (required)
EmailAddress (required)
Phone Number (optional)
Explanation:

This example uses the script tag to place a JavaScript function in the head element to see if two form fields (firstname and lastname) have been left blank. The form portion of the code is not included, but may be viewed on the form tag page.

Language(s): XHTML

See Also: