Javascript
JavaScript is a scripting language that is supported and runs on almost all web browsers,such as Internet Explorer,Mozilla,Firefox,Nestcape and Opera.
JavaScript was designed to add interactivity to HTML pages
By embedding JavaScript in an HTML page,parts of the Document Object Model (DOM) within the HTML document can be updated.
Example: A JavaScript function will be added into the HTML code above to handle the onClick event of the Login button. As the user clicks the button,the notification message:“The name is required field and can not be empty” will occur,if the user did not type in his name. The code as in following:
1: <html>
2: <head>
3: <script type=”text/javascript”>
4:
5: function validateUser()
6: {
7: name= document.getElementById(“userName”).value;
8: if (name == ””)
9: {
10: alert(“The name is required field and can not be empty”);
11: }
12: }
13:
14: </script>
15: </head>
16:
17: <body>
18:
19: <form id=”loginForm”>
20: <input type=”text” id=”userName”/>
21: <input type=”submit” id=”login” value=”Login” onClick=”validateUser()”/>
22: </form>
23:
24: </body>
25: </html>
26:
|