.

Archive for JavaScript

Font resizing using jQuery

// April 15th, 2009 // No Comments » // JavaScript

Font Resizing is a very common feature in many modern websites. This can be done very easily with jQuery. The following script uses cookies to save the user preference, so the user preference is saved. jQuery Cookie plugin is used for managing cookie using jQuery. So include that too.

the html for increase, decrease links

<div>
	<a href="javascript:void decreaseFont();" class="font-smaller" title="Reduce font size">-</a>
	<a href="javascript:void normalFont();" class="font-normal" title="Normal font size">0</a> 
	<a href="javascript:void increaseFont();" class="font-bigger" title="Increase font size">+</a>
</div>

Add the following code just before the tag.

(more…)

  • Share/Bookmark

Disable right-click contextual menu

// March 16th, 2009 // No Comments » // JavaScript

You can disable right-click contextual menu in your website using jQuery. Download and include jQuery library in your page and add the following code before the tag.
(more…)

  • Share/Bookmark

File extension validation Javascript

// February 27th, 2008 // 1 Comment » // JavaScript

You can use this function to validate the extension of a file, for client side file upload checkes.

// You can specify the file type in the code "valid_extensions = /(.doc|.pdf)$/i;" .
//If you want to add .docx supprt simply add |.docx (ex:(.doc|.pdf |.docx| .your-extension) ) 

var valid_extensions = /(.doc|.pdf)$/i;
function CheckExtension(fld)
{
	if(fld.value) {
		if (valid_extensions.test(fld.value)){
			return true;
		} else {
			return false;
		}
	} else {
		return true;
	}
}
  • Share/Bookmark

Javascript for validating a date

// February 26th, 2008 // No Comments » // JavaScript

Javascript for validating a date.

Pass month, day, year as parameters. This function will return true if the date is valid.

// Author: arunmvishnu.com
function validDate(month, day, year){
	if(month =='0' || day =='0' || year=='0'){
		return false;
	}

	switch(month){
		case '1': //** jan
		case '3': //** March
		case '5': //** May
		case '7': //** July
		case '8': //** Aug
		case '10': //** Nov
		case '12': //** Dec

		if(day >=1 && day <= 31){
			return true;
		} else {
			return false;
		}

		case '4': //** APRIL
		case '6' : //** JUNE
		case '9' : //** SEPTEMBER
		case '11' : //** NOVEMBER
		if(day >=1 && day <= 30){
			return true;
		} else {
			return false;
		}

		case '2' : // Feb
		if(isLeapYear(year)){
			if(day >=1 && day <= 29){
				return true;
			}
		} else if(day >=1 && day <= 28){
			return true;
		} else {
			return false;
		}
		default:
			return false;
	}
}

function isLeapYear(year){  // Checking wdr a year is leap year or not
	if(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)){
		return true;
	} else {
		return false;
	}
}

The full js file can be dodnloaded from here

  • Share/Bookmark