Tag: javascript

creating a custom popup in javascript

When we create a popup using javascript, we can provide a list of options to customize the appearance of popup window. In the following files, a popup is created. In the popup window, user is provided with options to input values. When the user clicks on close button on popup, the values are written on

disabling back button using javascript

By default browsers does not allow us to disable back button. However, when working with database applications, we often need to disable the back button. In this example, we disable the back button using javascript: <html> <head></head> <body> <h1>This is page 1</h1> <br><br> <input id="btnback" name="btnback" type="button" value="Back" onclick="window.history.back();" /> </body> </html>  

Controlling page navigation using javascript

In this example, we control the navigation dynamically using javascript <html> <head> <title></title> <script language="javascript" type="text/javascript"> function navigate() { window.location.href="page1.html"; } </script> </head> <body > <input id="btn" name="btn" type="button" value="click here" onclick="window.open('meta.html');" /> <input id="btn1" name="btn1" type="button" value="Go to Page1" onclick="window.location.href='page1.html';" /> <br /> <a href="page1.html">Page1.html</a> <br /> <a href="javascript:;" onclick="window.location.href='page1.html';">Page1.html</a> <br /> <a href="javascript:;"

accessing status bar using javascript

In this code script, we access the status bar using javascript. The status bar shows URLs and text when mouse is move over the hyperlinks. The status bar is present at bottom left of page. <html> <head> <title></title> <script language="javascript" type="text/javascript"> function statusBarText() { window.status = "This is text"; document.write(window.status); } </script> </head> <body onload="statusBarText();">

arrays in javascript

In this example, we learn how to create an array in javascript and how to traverse array. How to perform various built-in operations on array elements, such as sorting, etc. <html> <head> <title></title> <script language="javascript" type="text/javascript"> var instruments = new Array("piano", "drum", "flute"); //document.write(instruments.length); //document.write(instruments.toString()); var myarray = new Array(); myarray[0] = "pen"; myarray[1] =

Date operations using javascript

In this code, we use javascript to perform various operations on date <html> <head> <title></title> <script language="javascript" type="text/javascript"> var today = new Date(); //document.write(today); var newYear = new Date(2014,4,1); document.write(newYear.getDate()); var daysRemaining; daysRemaining = today - newYear ; //document.write(daysRemaining/86400000); </script> </head> <body> </body> </html>  

disable form posting using javascript

Sometimes we do not want user to submit form unless some conditions are met. In the following example, the user will be able submit form only if (s)he clicks on “I agree” checkbox. <!DOCTYPE html> <html> <head> <title>Untitled document</title> <meta charset="utf-8" /> <script language="javascript" type="text/javascript"> function enableButton() { var chk = document.getElementById("chkagree"); var btn =

validating html object array using javascript

In this example, we validate an array of checkbox, text, and radio fields. We also validate a html drop down “select” <!DOCTYPE html> <html> <head> <title>Untitled document</title> <meta charset="utf-8" /> <script language="javascript" type="text/javascript"> function validate() { var currency = document.getElementById("txtcurrency").value; var country = document.getElementById("ddlcountry"); var radsuit = document.getElementsByName("radSuit"); var chkSuit = document.getElementsByName("chkSuit"); var status=false; var