November 4, 2016

How to get timezone of client machine with JavaScript?

function formatedZone() { var now = new Date(), tzo = -now.getTimezoneOffset(), dif = tzo >= 0 ? ‘+’ : ‘-‘, pad = function(num) { var norm = Math.abs(Math.floor(num)); return (norm < 10 ? ‘0’ : ”) + norm; }; return dif+pad(tzo / 60)+ ‘:’ +pad(tzo % 60); }

June 30, 2015

JavaScript error td_mobile_menu is not defined

JavaScript error td_mobile_menu is not defined Solution: if (typeof td_mobile_menu == ‘function’) { td_mobile_menu(); }

May 17, 2015

jQuery contains vs. JavaScript indexOf to filter results

jQuery contains vs. JavaScript indexOf to filter results $(‘#sess_input’).on(‘keyup’, function(){ var filter = $(this).val(); $(“#sess_table .sess_rows”).each(function() { var found = $(this).text().toLowerCase().indexOf(filter); if(found

September 20, 2012

Mouse click activity, mousedown, mouseup and click

Mouse click activity

Mouse click activity, mousedown, mouseup and click Javascript related event handlers like onmousedown, onmouseup and onclick are the subdivisions of an event. These events are triggered by mouse click which is subdivided into the following: onmousedown onmouseup onclick To understand this activity we have to guess that when we press mouse button “left click” that […]

August 29, 2012

SyntaxError: unterminated string literal – PHP/XHTML String

SyntaxError: unterminated string literal – PHP/XHTML String <?php $string = addslashes(preg_replace(“/[\r\n]+/”,’ ‘,(preg_replace(‘/\s\s+/’, ‘ ‘, include(“xhtml_page.php”)))); ?> Note: New lines in string will be removed and the string will be a valid string instead of unterminated string in javascript. <script type=”text/javascript” language=”javascript”>var js_str = ‘<?php echo $string; ?>’;</script>

August 16, 2012

onKeypress enter return false;

onKeypress enter return false; function checkEnter(e){ var key; if (window.event) key = window.event.keyCode; else if (e) key = e.which; var ret = ((key) != 13); return ret; }

August 15, 2012

JavaScript Replace All Function

JavaScript Replace All Function function replaceSubstring(inSource, inToReplace, inReplaceWith) { return inSource.replace(new RegExp(inToReplace, ‘g’),inReplaceWith); }

June 20, 2012

javascript regular expression for alphabets and space

js regular expression for alphabets and space Note: A useful javascript function which i mostly use to manage names and related fields validation. function checkName(field,title) { var val = $(“#”+field).val(); var re = /^([a-zA-Z _-]+)$/; if(val.length<1) { $(‘#error_’+field).text(title+’ is required.’); $(‘#error_’+field).addClass(‘error-msg’); return false; } else if(!re.test(val)) { $(‘#error_’+field).text(‘Please enter a valid name.’); $(‘#error_’+field).addClass(‘error-msg’); return false; […]