- JavaScript made its first appearance in Netscape 2.0 in 1995 with the name LiveScript.
- It is a dynamic computer programming language and it helps to develop the dynamic web pages.
- We use JavaScript to program the behavior of web pages and also we can validate the HTML forms using JavaScript.
- JavaScript is a case-sensitive language and Semicolon's were optional.
- Keyword var is used to create a new variable.
- Script tags can be added in <head> (or) <body> (or) from an external file.External scripts can be included using the code <script src="src.js"></script>.
- Allows three primitive data types.
- Numbers
- Strings
- Boolean
JavaScript to change HTML content:
- document.getElementById("idname").innerHTML
- document.getElementById("idname").value
- document.getElementById("idname").style.fontSize;
- document.getElementById("idname").style.color;
- window.alert();
- window.confirm();
- window.prompt("","");
- document.write();
INNERHTML
- Explanation
- EXAMPLE CODE 1
- EXAMPLE CODE 2
-
document.getElementById("idname").innerHTML="Value or content";
Explanation:
We are getting the elements within the Id using id name.
InnerHTML indicates that the content within that Id name.
The code describes that the content inside that id name will be replaced by the content within the "double codes".
(or)
-
var x = document.getElementById("idname").innerHTML;
VALUE
- Explanation
- EXAMPLE CODE 1
-
var x = document.getElementById("idname").value;
Explanation:
Using the above code, we can get the value of the element with the id name as "idname".
We can get the value of the element by mentioning id name to compare or to calculate.
(or)
-
document.getElementById("idname").value="Name";
Explanation:
We can assign the value for the element by mentioning id name.
STYLE
- Explanation
- EXAMPLE CODE 1
- EXAMPLE CODE 2
-
document.getElementById("idname").style.fontSize="_px";
Explanation:
[Note: In the above word for fontSize 'S' is in upper case]
Using the above JavaScript code we can change the font-size of the content with the id name as "idname".
Size must be mentioned in the pixels.
-
document.getElementById("idname").style.color="clr nme";
Explanation:
The font color of the elements with id as idname can be changed using the above JavaScript code.
POP-UP Window
- EXPLANATION
- EXAMPLE CODE 1
- EXAMPLE CODE 2
- EXAMPLE CODE 3
-
window.alert(" Alert message");
Explanation: Using this function we can display an alert message to the users in JavaScript.
-
window.confirm("Some Text");
Explanation: Using this function we can get the confirmation from the user whether ok (or) cancel.
-
window.prompt("sometext","defaultText");
Explanation: Using this function we can get the value from the user in form of an POP UP window.
WRITE
- EXPLANATION
- EXAMPLE CODE 1
- EXAMPLE CODE 2
-
document.write("Sometext");
Explanation: If we use document.write function in JavaScript after an HTML document is fully loaded , then it will delete all the existing HTML. You can understand easily by running the codes in Example code 1 & Example code 2.
HTML Forms
- EXPLANATION
We can use text box, Radio Buttons, Drop down list box, Text area, etc. We cannot set constraints in HTML but it can be done using JavaScript. To see how create a Html form. Click Here
JavaScript Form Validation
- EXPLANATION
- EXAMPLE CODE 1
- HTML forms can be validated using JavaScript by which we can set some constraints.
- Getting the value or input from the users and we can validate it.
- We can get the value using the 'name' or 'idname'.

