Introduction to JavaScriptJS is very much like Java in syntax, although execution engine is very different. Following constructs are exactly same:
JS does everything by referring to a variable called document which refers to the current page. Example:
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post"> First name: <input type="text" name="fname"> <input type="submit" value="Submit"> </form> <script> function validateForm() { var x=document.forms["myForm"]["fname"].value; // do some validation here return true; } </script>
JS can basically access any field of an HTML construct as shown above. So, this can also be used to add dynamism to web pages by calling JS scripts on events.
|
Got a thought to share or found a
bug in the code?
We'd love to hear from you:
Name: | |
Email: | (Your email is not shared with anybody) |
Comment: |
Facebook comments: