jQuery validation to allow only numbers OR only characters

Allow only numbers 

if(event.which != 8 && isNaN(String.fromCharCode(event.which))){



Allow Characters with dots

var inputValue = event.charCode;  if(!(inputValue >= 65 && inputValue <= 120) && (inputValue != 32 && inputValue != 0  && inputValue != 46)){




Browser close & reload events in jQuery

/*Browser close jQuery event*/
Put this code body tag –> onunload=”doUnload()”

Below code for script
function doUnload()
if(window.event.clientX < 0 && window.event.clientY <0){
var cookieName = ‘suitebeb123’;

/*Broser reload javascript function*/
window.onbeforeunload = function (e) {
// Your logic to prepare for ‘Stay on this Page’ goes here

Smooth Scroll using jQuery

Please find below code for smooth scroll

$(“a”).on(‘click’, function(event) {
if (this.hash !== “”) {
var hash = this.hash;
$(‘html, body’).animate({
scrollTop: $(hash).offset().top
}, 1800, function(){
window.location.hash = hash;

window.location in javascript

Please find below code…

//Get current page url
var curr_url = window.location.href

//Get hostname
var host_name = window.location.hostname

//Display the path name of the current URL
var path_name = window.location.pathname

//Get protocol of URL return http:// or https://
var proto = window.location.protocol;

//Get parameters from URL
var x = location.search;

HTML 5 Standard Events in JavaScript

Offline => Triggers when the document goes offline
Onabort => Triggers on an abort event
onafterprint => Triggers after the document is printed
onbeforeonload => Triggers before the document loads
onbeforeprint => Triggers before the document is printed
onblur => Triggers when the window loses focus
oncanplay => Triggers when media can start play, but might has to stop for buffering
oncanplaythrough => Triggers when media can be played to the end, without stopping for buffering
onchange => Triggers when an element changes
onclick => Triggers on a mouse click
oncontextmenu => Triggers when a context menu is triggered
ondblclick => Triggers on a mouse double-click
ondrag => Triggers when an element is dragged
ondragend => Triggers at the end of a drag operation
ondragenter => Triggers when an element has been dragged to a valid drop target
ondragleave => Triggers when an element is being dragged over a valid drop target
ondragover => Triggers at the start of a drag operation
ondragstart => Triggers at the start of a drag operation
ondrop => Triggers when dragged element is being dropped
ondurationchange => Triggers when the length of the media is changed
onemptied => Triggers when a media resource element suddenly becomes empty.
onended => Triggers when media has reach the end
onerror => Triggers when an error occur
onfocus => Triggers when the window gets focus
onformchange => Triggers when a form changes
onforminput => Triggers when a form gets user input
onhaschange => Triggers when the document has change
oninput => Triggers when an element gets user input
oninvalid => Triggers when an element is invalid
onkeydown => Triggers when a key is pressed
onkeypress => Triggers when a key is pressed and released
onkeyup => Triggers when a key is released
onload => Triggers when the document loads
onloadeddata => Triggers when media data is loaded
onloadedmetadata => Triggers when the duration and other media data of a media element is loaded
onloadstart => Triggers when the browser starts to load the media data
onmessage => Triggers when the message is triggered
onmousedown => Triggers when a mouse button is pressed
onmousemove => Triggers when the mouse pointer moves
onmouseout => Triggers when the mouse pointer moves out of an element
onmouseover => Triggers when the mouse pointer moves over an element
onmouseup => Triggers when a mouse button is released
onmousewheel => Triggers when the mouse wheel is being rotated
onoffline => Triggers when the document goes offline
onoine => Triggers when the document comes online
ononline => Triggers when the document comes online
onpagehide => Triggers when the window is hidden
onpageshow => Triggers when the window becomes visible
onpause => Triggers when media data is paused
onplay => Triggers when media data is going to start playing
onplaying => Triggers when media data has start playing
onpopstate => Triggers when the window’s history changes
onprogress => Triggers when the browser is fetching the media data
onratechange => Triggers when the media data’s playing rate has changed
onreadystatechange => Triggers when the ready-state changes
onredo => Triggers when the document performs a redo
onresize => Triggers when the window is resized
onscroll => Triggers when an element’s scrollbar is being scrolled
onseeked => Triggers when a media element’s seeking attribute is no longer true, and the seeking has ended
onseeking => Triggers when a media element’s seeking attribute is true, and the seeking has begun
onselect => Triggers when an element is selected
onstalled => Triggers when there is an error in fetching media data
onstorage => Triggers when a document loads
onsubmit => Triggers when a form is submitted
onsuspend => Triggers when the browser has been fetching media data, but stopped before the entire media file was fetched
ontimeupdate => Triggers when media changes its playing position
onundo => Triggers when a document performs an undo
onunload => Triggers when the user leaves the document
onvolumechange => Triggers when media changes the volume, also when volume is set to “mute”
onwaiting => Triggers when media has stopped playing, but is expected to resume

Google Maps traffic layer

<style type=”text/css”>
html { height: 100%;}
body { height: 100%; margin: 0px; padding: 0px; }
#map { height: 600px; width: 600px; }

/* script call here

http://maps.google.com/maps/api/js?sensor=false&#8221; type=”text/javascript”

/*script start here*/
google.maps.event.addDomListener( window, ‘load’, init );

function init() {
var options = {
zoom: 7,
center: new google.maps.LatLng( 32.715738, -117.161084 ),
mapTypeId: google.maps.MapTypeId.ROADMAP,
overviewMapControl: false
var map = new google.maps.Map( document.getElementById( “map” ), options );
var traffic = new google.maps.TrafficLayer();
traffic.setMap( map );

document.getElementById( ‘b’ ),
function() {
traffic.setMap( traffic.getMap() === null ? map : null )
} );
/*script end here*/

HTML tags in Textarea

<form action=”” name=”myForm” method=”post”>
[&nbsp;<span class=”intLink” onclick=”insertMetachars(‘&lt;strong&gt;’,’&lt;\/strong&gt;’);”><strong>B</strong></span> | <span class=”intLink” onclick=”insertMetachars(‘&lt;em&gt;’,’&lt;\/em&gt;’);”><em>I</em></span> | <span class=”intLink” onclick=”var newURL=prompt(‘Enter the full URL for the link’);if(newURL){insertMetachars(‘&lt;a href=\u0022’+newURL+’\u0022&gt;’,’&lt;\/a&gt;’);}else{document.myForm.new_subspecify.focus();}”>URL</span>]<br>
<input type=”text” id=”doct_specialty” value=”” name=”new_subspecify”><br>
<input type=”submit” value=”Save” id=”butt_specialty” name=”hosp_services”>
function insertMetachars(sStartTag, sEndTag) {
var bDouble = arguments.length > 1, oMsgInput = document.myForm.new_subspecify, nSelStart = oMsgInput.selectionStart, nSelEnd = oMsgInput.selectionEnd, sOldText = oMsgInput.value;
oMsgInput.value = sOldText.substring(0, nSelStart) + (bDouble ? sStartTag + sOldText.substring(nSelStart, nSelEnd) + sEndTag : sStartTag) + sOldText.substring(nSelEnd);
oMsgInput.setSelectionRange(bDouble || nSelStart === nSelEnd ? nSelStart + sStartTag.length : nSelStart, (bDouble ? nSelEnd : nSelStart) + sStartTag.length);