Skip to main content

Posts

Showing posts from August, 2011

Escape key Event

Demo Press Esc Code <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script type="text/javascript"> $(document).keyup(function(event) { if (event.which == 27) { $('#butt').click(); } }); $(document).ready(function(){ $("#butt").click(function() { alert('Man'); }); a }); </script> <button id="butt" >Press Esc</button>

Date Difference

$date1 = date("Y-m-d"); $date2 =$row[0]; $diff = abs(strtotime($date2) - strtotime($date1)); $years = floor($diff / (365*60*60*24)); $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); printf("%d years, %d months, %d days\n", $years, $months, $days);

Trigger Button click on key stroke JavaScript

Demo Press A Code <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).keydown(function(event) { if (event.which ==65) { $('#butt').click(); } }); $(document).ready(function(){ $("#butt").click(function() { alert('Man'); }); }); </script> </head> <body> <button  id="butt" >Press A</button> </body> </html>

Simple Jquery Multiplication

Demo 2 X = Code <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#txt1").keyup(function(){ if(this.value!="") $(this).closest('td').next().text(parseInt($("#txt1").val())*parseInt($("#td1").text())); else $(this).closest('td').next().text(""); }); }); </script> </head> <body> <table> <tr> <td id="td1">2 X </td> <td><input type="text" id="txt1">=</td> <td></td> </tr> </table> </body> </html>

Distinguishing Mouse buttons

Demo  Right Click here Code <HTML><HEAD> <script language="javascript"> function click(e) { if (navigator.appName == 'Netscape' && e.which == 3) { alert("no right click please") return false; } else { if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) alert("no right click please") return false; } return true; } document.onmousedown=click </script> </HEAD> <BODY> No right mouse button here! </BODY></HTML>

Context Menu (Right click) JavaScript

<html><head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" > $(document).ready(function(){ $('#rightclickarea').bind('contextmenu',function(e){ $('<div>').click(function(){}).bind('contextmenu' , function(){return false;}).appendTo(document.body); $(this).next().css({ left: e.pageX, top: e.pageY, zIndex: '101' }).show(); return false; }); $('.vmenu .first_li').click(function() { if($(this).children().text()=="Refresh") location.reload(); }); $(".first_li").hover(function () { $(this).css({backgroundColor : '#E0EDFE' , cursor : 'pointer'}); }, function () { $(this).css('background-color' , '#fff' ); }); $(document).click(function(){$('.vmenu').hide();}); }); </script> <style> .vmenu{border:1px solid #aaa;position:absolute;background:#f