Posts

How to insert the data in a web page dynamically?

To insert the data in a web page dynamically use <div></div> tag or <span></span> tag The data inserted with  <div></div> goes to new line. It is a block tag. The data inserted using <span></span> tag remains in same line. It is inline tag. Define an ID to these tags and get reference of that  ID using document.getElementById() function Use innerHTML property to insert HTML contents Use innerText properyt to insert the Text contents. Example 1 Create a web page having a multiline text box using <textarea></textarea> tag. When we type some HTML code into the web page, show the code along with its output in same web page. Hint: Event will be keyup <! DOCTYPE html > <html>     <head>         <script>             function display (){                 var x = document . getElementById ( "x" );...

How tags communicate with each other?

To provide the communication among the tags, we need to give some identification to the tags using ID attribute. Example <input type = "text" id = "num" > <input type = "text" id = "result" > To communicate with a tag, we need to get reference of it inside memory using  getElementById() function of document object Use var keyword to define the variables to get reference of the tags Example var x=document.getElementById("num"); var y=document.getElementById("result"); Now we can use the value property to read the data or write the data Note: All the values received from the input tags are of string type. If we want to do some numerical calculation on the data, we need to convert the string data to numeric data using data conversion functions parseInt() and parseFloat() Example var n=parseInt(x.value); Sample Case Create a web page having two text boxes, first one to input a number and second one to show a re...

What are different ways to use the JavaScript?

 JavaScript can be used using three ways Immediate Script Code get executed automatically when  we load a web page Deferred Script Code get executed based on some event We need to create a function to link with some event attribute Use function keyword to define the functions in the JavaScript   Hybrid Script Some code get executed at the time of loading the page and other code get executed based on some event Example of Immediate Script <script> //immediate script code alert("Welcome to JavaScript"); </script> Example of Deferred Script <script> function welcome(){ alert("OOPs! You Clicked"); } </script> <input type="button" value="Click Me" onClick="welcome()"> Example of Hybrid Script <script> alert("This is an example of Hybrid Script"); function welcome(){ alert("OOPs! You Clicked"); } </script> <input type="button" value="Clic...

Some common functions used in JavaScript

 JavaScript provides some built-in functions to perform different operations alert(message) function Used to show a dialog confirm(message) function Used to ask something from you with Ok and Cancel buttons If clicked on Ok button then treated as true else treated as false

What is JavaScript?

A scripting language that get merged into HTML to create dynamic contents at the client side using other related technologies of Dynamic HTML known as Document Object Model (DOM), Events, JSON, AJAX etc. HTML provides <script></script> tag to merge the JavaScript code into HTML. It is developed by Netscape and it is based on Java . JavaScript can also be used at the server side using Node.js to build the dynamic websites. There many technologies build based on JavaScript like React.js, Angular.js, Vue.js etc.