javascript function for responsive design

function max_width(w) {
   if(window.innerWidth <= w) {
   } else {


JavaScript money format

var profits=2489.8237
  profits.toFixed(3)//returns 2489.824 (round up)
  profits.toFixed(2)//returns 2489.82
  profits.toFixed(7)//returns 2489.8237000 (padding)


Javascript serializeObject function

[code] $.fn.serializeObject = function() { var o = {}; var a = this.serializeArray(); $.each(a, function() { if (o[] !== undefined) { if (!o[].push) { o[] = [o[]]; } o[].push(this.value || ''); } else { o[] = this.value || ''; } }); return o; }; [/code]


jqPlot jQuery Javascript framework for plotting and charting

jqPlot is a plotting and charting plugin for the jQuery Javascript framework. jqPlot produces beautiful line, bar and pie charts with many features:


Leafleft An Open-Source JavaScript Library for Mobile-Friendly Interactive Maps

An Open-Source JavaScript Library for Mobile-Friendly Interactive Maps Leaflet is a modern open-source JavaScript library for mobile-friendly interactive maps. It is developed by Vladimir Agafonkin with a team of dedicated contributors. Weighing just about 33 KB of JS, it has all the features most developers ever need for online maps.


Google Maps

latitude, longitude Drawing on map marker info windows Waypoints polyline polygons Directions service Keywords : travel modes, street view      


bootstrap & fancybox conflict

it can be solved by  fancy  beforeLoad
$(document).ready(function() {
 var fancy_top = "";
 'width' : '75%',
 'height' : '75%',
 'autoScale' : false,
 'transitionIn' : 'none',
 'transitionOut' : 'none',
 'type' : 'iframe',
 'afterClose' : function() {
  $('html, body').animate({ scrollTop:fancy_top });},
 'beforeLoad' : function() { 
  var fancy_top = document.body.scrollTop; 





Multiple CKEditor replace by class with same class in one page

CKEditor replace  by class with same class in one page <textarea cols="80"  class="editor"   name="editor1" rows="10"> ddd</textarea> <textarea cols="80"    class="editor"  name="editor2" rows="10"> ddd</textarea>


var dd=1;


CKEDITOR.replace( 'editor'+dd);



jQuery change select form by value

[php] function change_option_byvalue(select,value){ $(select).find("option:selected").removeAttr("selected"); $(select).find("option[value='"+value+"']").attr('selected','selected'); $(select).find("option[value='"+value+"']").trigger('click'); var selectparent =$(select).parent(); var newselect =$(select).clone(); $(select).remove(); selectparent.append(newselect); } change_option_byvalue("select[name='muslum']",21);  // it will select the option that has value of 21 by muslum21 [/php]


next day function by muslum21

[php] function next_day(date,next_day){ var expire_date1= new Date(date); //console.log(expire_date1); expire_date1.setDate(expire_date1.getDate()+next_day); expire_date1.setMonth(expire_date1.getMonth()+1); return expire_date1.getMonth()+'/'+expire_date1.getDate()+'/'+expire_date1.getFullYear() ; } next_day('01/21/2013',2);  // return '01/23/2013' &nbsp; [/php]


geting js ajax json object result to console as key value with jquery $each() function

dd geting js ajax json object result to console as  key value  with jquery $each() function [php]</p> <p>var result = jQuery.parseJSON(response.responseText);<br /> //console.log(result);<br /> $.each(result, function(key, value){<br /> $.each(value, function(key, value){</p> <p>console.log(key, value);<br /> });<br /> });</p> <p>[/php]


php strpos - javascript equivalent [php] function strpos (haystack, needle, offset) { // // + original by: Kevin van Zonneveld ( // + improved by: Onno Marsman // + bugfixed by: Daniel Esteban // + improved by: Brett Zamir ( // * example 1: strpos('Kevin van Zonneveld', 'e', 5); // * returns 1: 14 var i = (haystack + '').indexOf(needle, (offset || 0)); return i === -1 ? false : i; } strpos('Kevin van Zonneveld', 'e', 5); // return 1,14 [/php]


Enter key on html form submission

[php] <pre><script> function testfunction(){ document.Add.submit(); } </script></pre> <form action="" method="post" name="Add" id="Add"  enctype="multipart/form-data" onkeypress="if(Enter(event)==true){ return testfunction () }"> [/php] --------


loading a page effect

[php] <style type="text/css" id="page-css"> #loading { z-index:1000; position:absolute; width:100%; height:100%; overflow:hidden; background-color:#fff;} #loading .middle { position:absolute; width:100%; margin-top: -24px; top: 50%; height:52px; text-align:center;} #loadingBg { position:absolute; width:100%; height:100%; overflow:hidden; background-color:#fff; display:none;} #loadingBg .middle { position:absolute; width:100%; margin-top: -24px; top: 50%; height:52px; text-align:center;} </style> <script type="text/javascript" id="sourcecode"> window.onload = function() { $("#loading").delay(100).fadeOut(1000); } </script> <body> <div id="loading"> <div class="middle"> <div class="inner"> <img src="{RootDir}{TempDir}assets/css/img/yukleniyor.gif" alt="" /> </div> </div> </div> [/php]


How to prevent form submission by pressing enter key

[php] <script language="javascript" type="text/JavaScript""> document.onkeypress = keyPress; var count = 1; function keyPress() { if (window.event.keyCode == 13) { event.returnValue=false; event.cancel = true; } } </script> [/php] OR [php] <body OnKeyPress="return disableKeyPress(event)"> <script language="JavaScript"> function disableEnterKey(e) { var key; if(window.event) key = window.event.keyCode; //IE else key = e.which; //firefox return (key != 13); } [/php] modified by muslum21 for jquery [php] $("body").keydown(function (e) { var key; if(window.event) key = window.event.keyCode; //IE else key = e.which; //firefox return (key != 13); }); </script> [/php] Here is a modified version of my function. It does the following: Prevents the enter key from working on any element of the form other than the textarea, button, submit. The enter key now acts like a tab. preventDefault(), stopPropagation() being invoked on the element is fine, but invoked on the form seems to stop the event from ever getting to the element. So my workaround is to check the element type, if the type is not a textarea (enters permitted), or button/submit (enter = click) then we just tab to the next thing. Invoking .next() on the element is not useful because the other elements might not be simple siblings, however since DOM pretty much garantees order when selecting so all is well. [php] function preventEnterSubmit(e) { if (e.which == 13) { var $targ = $(; if (!$"textarea") && !$":button,:submit")) { var focusNext = false; $(this).find(":input:visible:not([disabled],[readonly]), a").each(function(){ if (this === { focusNext = true; } else if (focusNext){ $(this).focus(); return false; } }); return false; } } } &nbsp; [/php]


javascript - trim functions

  [code] &nbsp; function ltrim(str) { for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++); return str.substring(k, str.length); } function rtrim(str) { for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ; return str.substring(0,j+1); } function trim(str) { return ltrim(rtrim(str)); } function isWhitespace(charToCheck) { var whitespaceChars = " \t\n\r\f"; return (whitespaceChars.indexOf(charToCheck) != -1); &nbsp; [/code]


javascript split() and join() functions epual to the function explode() and implode() in php

[code] var str="How are you doing today?"; var n=str.split(" "); [/code] The result of n will be an array with the values: How,are,you,doing,today? [code] var fruits = ["Banana", "Orange", "Apple", "Mango"]; var energy = fruits.join(); [/code] The result of energy will be: Banana,Orange,Apple,Mango