Archive for "Javascript"
Jun04Javascript common mistake of comparing with NaN and not with isNaN
Recently, i fell into the trap of NaN and isNaN and it turned me pulling my hair for quite a few good minutes. Thats why i decided to make a note of it here for a recitation and as a note of reference for myself for future. Click to continue »
Jun03How to prevent parent’s onclick event from firing when a child tag is clicked with jquery?
Generally, Javascript events bubble (listen) to the highest point in the DOM to which a click event had been attached. So even if you don’t have any other explicitly click-able elements in the div, every child element of the div would bubble their click event up the DOM to until the DIV’s click event handler catches it. Click to continue »
Apr02Gmail like ajax loading message at the top of page
Here is a sample javascript code to show Gmail like “Loading.. Please wait..” message at the top of a HTML page while making Ajax requests. Irrespective of the position of Ajax links within web page, the “Loading” message will show at the very top of the page. Click to continue »
Jan30Autocomplete=”off” workaround / fix for valid XHTML
Add an onload function similar to the following to <head> section of your web page.
<script type="text/javascript">
function onload_call() {
if (!document.getElementById) return false;
var f = document.getElementById('field_name');
f.setAttribute("autocomplete", "off");
}
</script>
Jan30Checking / Unchecking radio buttons and retrieving their value in jQuery
Let us assume we have radio buttons
<input name="rd_name" id="RD1" value="Value One" /> Label 1 <input name="rd_name" id="RD2" value="Value Two" /> Label 2
To retrieve and set radio button values by id we have the following methods. To retrieve we have, Click to continue »
Jan27Invoking Lightbox2 slide show on page load
Invoke Lightbox2 on page load? Good question! If you have got frustrated searching for a solution to it, relax, it’s here!
Just place the following snippet of javascript code in your web page’s <head> section: Click to continue »
Jan14Browser detect script in javascript
I found this useful and up-to-date article to detect browser in JavaScript. Please refer to the author’s site page for detailed explanation. Click to continue »
Jan08When Firebug made life easier
It’s been around three years now i have been using the Firebug. This great tool provides a web developer an easy way to look at and inspect the source code of a web page. You can view and experiment with each and every part of your web page and related DOM elements, inline or linked CSS, JavaScript and not to say the entire page content. Click to continue »
Nov27How to position a pop up element on mouse position coordinates with jquery
Here is a simple yet useful trick to position a tooltip (a div element etc) near the mouse click or pointer position using jQuery. In the example here, we have a tool tip (div) with id “tooltip”, a href tag, on clicking which the pop up is positioned and a snippet of code to place anywhere on the page. Obviousaly this small function can be used to return mouse event coordinates by makeing slightest changes.
I have not tested this code jquery version prior to 1.3.2.
So, here is the javascript code:
$(document).ready(function() {
$("#tooltip_link").click(function(e){
var x = e.pageX;
var y = e.pageY;
alert(x +', '+ y);
$("#tooltip").css({"top":y, "left":x, "position":"absolute"});
$(this).unbind('click');
});
}
The code line below is used to stop click event when action is already over:
$(this).unbind('click');
And href and div tag html code:
CLICKOnce there was a man who lived in a forest. He ate in the forest and slept in the forest. He was very happy living in the forest. At last he died in the forest. No one knows why the man lived in the forest. I know this is not a happy story. The end!
Nov14Positioning a pop up element on a browser window
While working in my last CakePHP project i needed a piece of javascript code that should help me in positioning a absolute pop up element near mouse click. I had been using prototype library for javascript stuff so i looked around for something real quick and useful to position element Click to continue »





