JavaScript
Validate a Check Box Using JavaScript
Using javaScript it is possible to check whether a check box has been checked or not. This is handy if you need your users to agree to the terms and conditions before they sign up. A check box has a checked property, which returns either a 0 for not checked and a 1 for checked. Following code shows how you can validate the checkboxes.
Automatic Redirect using Javascript
You can redirect your users from the current page to a desired page using JavaScript. Please use the following code to do so:
| CODE |
|
<script type="text/javascript"> <!-- window.location.href = "http://www.w3courses.com/" //--> </script> |
Multi Level Drop Down Category & Subcategory Hierarcheal Selection using JavaScript
This code will enable you to populate the list of states depending on the country selection. For example if you choose United States in the country drop down selection, the state drop down will contain Alaska, California etc. Else if you choose Canada, the state drop down list will contain Alberta, British Columbia etc.
All of this is done without reloading the page. This script could also be used in other formats, e.g., automobiles: type/make/model; or books: publisher/author/title. In order implement this script, perform the instructions below:
Flash and JavaScript Conflict: Javascript Menu goes behind the flash file
Sometimes if you use flash and javascript on the same page, you will have some problem with your layers or javascript. The most common problem is that the javascript menu or other control goes behind the flash file. I am sure you have tried many things like changing the z-index or putting flash more down but the solution is simpler than that. How? You have to make your flash transparent and everyting will be okay.
Display Current Date Automatically on your Website using JavaScript
The following code displays the current date with month and year in the following format:
September 20, 2007
<script>
<!-- //Hide From Old Browsers
/*
Do Not Remove the Following Line
For more scripts visit http://www.w3courses.com
*/
How to Create a Reload Button which will Reload the Webpage upon Clicking using JavaScript
The following code will add a reload button to your webpage. This button will reload your webpage when clicked.
Place the following code in the body section of your webpage where you want to display the button
<form>
<INPUT TYPE="button" VALUE="Reload" onClick='parent.location="javascript:location.reload()"'>
</form>
Automatically Redirect from one Webpage to Another Webpage using JavaScript
Add the following code to the head section of your webpage to automatically redirect your users to another page.
<SCRIPT>
location.href = "http://www.w3courses.com"
</SCRIPT>
How to Display a Webpage in the PopUp Window after Clicking from a Link using JavaScript
The following code will add a link to your webpage and when clicked on the link, the hyperlinked webpage will open in a popup window
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=600,left = 262,top = 84');");
}
Disable Right Clicking on Webpage, Images and Photos with JavaScript
Add the following code to the head section of your html document to disable right clicking on your webpage. This way, users wll not be able to right click and save pictures or photographs from your website.
Note: However, users can use other ways to save the photos from your website such as looking at the source code and browsing to the location of the picture and then save it.
<script language=JavaScript>
<!-- //Hide from old Browsers
Automatically Display the Current or Today's Date with JavaScript
Add the following code to your html page where you want today's date to be displayed automatically
<script>
<!-- //Hide From Old Browsers
/*
Do Not Remove the Following Line
For more scripts visit http://www.w3courses.com
*/
