JavaScript Archive

document.getElementById

getElementById is a function in JavaScript to access the HTML elements. It’s a function of document object and can only access by using document.getElementById. Example : <html> <script> function sum() { var num1 = document.getElementById(‘num1’); var num2 = document.getElementById(‘num2’); var res = document.getElementById(‘result’); res.value = parseInt(num1.value) + parseInt(num2.value); } </script> <body> Enter First Number :

Array in JavaScript

Array is use to store multiple values in a one variable. Example 1: <script> var a = new Array(); a[0] = 2; alert(a[0]); </script> Example 2: <script> var b = new Array(78,4,5,3,5,7); for(i=0; i < b.length; i++) { alert(b[i]); } </script> Example 3: <script type=”text/javascript”> var ar = new Array(“Ram”,”Deep”,”Ravi”,”Mohit”); for (i=0; i

Popups in javascript

There are three kinds of popup boxes in JavaScript Who to define array in php? Alert box Alert box display message with ok button Example: <html> <script> alert(“Hello Viewers”); </script> </html> Confirm box Confirm box display message with ok and cancel button, it is use to take user confirmation. If we click ok, it returns

Ways of Adding JavaScript code

Following are the ways to add JavaScript in html page. Inline : JavaScript code that we writes inside html tags are called inline JavaScript, useful to write short code in JavaScript. Example: <html> <body> <input type=”button” onclick=”alert(‘hello’)” value=”Hello”/> <input type=”button” value=”Delete” onclick=”return confirm(‘Sure To Delete’)”/> </body> </html> Internal : JavaScript written in same html page

Advantages of javaScript

Easy to learn : JavaScript has simple, easy to learn syntax that we can use with html. Runs on Client Side : JavaScript runs on client side, means it use our own system memory(RAM,etc.) to run, so it’s faster than the server side scripting language, that use server’s memory. Features of programming languages : JavaScript