Posts

Showing posts from 2013

Geo Location - Get location based on where you are

Hi, Today i am going to share script how to get location based on where you are located.  Here is the script, <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>GMap location</title> <script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.min.js"> </script> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> <script> $(document).ready(function() {  navigator.geolocation.getCurrentPosition(function (pos) {     var geocoder = new google.maps.Geocoder();     var lat = pos.coords.latitude;     var lng = pos.coords.longitude;     var latlng = new google.maps.LatLng(lat, lng);      //reverse geocode the coordinates, returning location information.     geocoder.geocode({ 'latLng': latlng }, function (results, st...

Javascript function to display 2 digit number

Hi, Today i am going to share how to display 2 digit number in javascript and jQuery, Javascript: ------------- function twodigit(num) {          var num1 = parseInt(num, 10);           return num1 < 10 ? "0" + num1 : num1;     } JQuery: --------- $('#count').text(function(i,num) {   var num1 = parseInt(num, 10);   return num1 < 10 ? "0" + num1 : num1; }); Output: ---------- twodigit(1); // returns 01 twodigit(2); // returns 02

Upload folder for images

Image
Here i am going to explain how to upload folder instead of files. For that we need to add  webkitdirectory=""  inside the input tag in HTML For eg, <input type="file" name="file_input[]" id="file_input" multiple="" webkitdirectory=""> Output:

GMap Location Pointer based on Longitude and Latitude

Image
In this post, i am going to share how to display gmap pointer based on longitude and latitude. Here is the code, <!DOCTYPE html> <html> <head>   <meta http-equiv="content-type" content="text/html; charset=UTF-8">   <title> GMap location </title>   <script type='text/javascript' src="http://maps.google.com/maps/api/js?sensor=false&.js"></script>   <style type='text/css'>     #map_canvas{         width: 600px;         height: 500px;     }   </style>   </head> <body> <div id="map_canvas"></div> <script type='text/javascript'>//<![CDATA[ var map; var global_markers = [];    var markers = [[37.09024, -95.712891, 'trialhead0'], [-14.235004, -51.92528, 'trialhead1'], [-38.416097, -63.616672, 'trialhead2']]; var infowindow = new google.map...

Array to JSON

To display array values in JSON format, you need to use json_encode(). For eg: $arr = array('username' => 'test','userid' =>'1', 'password' => 'test123'); // Use json_encode to return in json format echo json_encode($arr); Output: {"username":"sham dhar","userid":"36","password":"test123"}

Trigger event on Hiding modal box

Some of the peoples will be using this for Bootstrap3 to hide modal box. Some may be facing issues on using this function, $('#myModal').on('hidden.bs.modal', function () {    alert("hii"); }); So, here is the solution for all who are all facing issues, This function will work in all the browsers where as, the above function will not work in some browsers such as chrome, etc. $('#myModal  button').click(function () {     $('#myModal iframe').removeAttr('src'); });

Breezing forms - Get datas from database

Copy the below code in your breezing forms by selecting your form, Go to Advanced -> More options -> Select "Form scripts" -> After Form or Before form its up to your requirement. // load the standard form creation utilities $this->execPieceByName('ff_InitLib'); //set globals global $record; //query db  $rows = ff_select("select * from `#__users`"); $html = ''; foreach ($rows as $row) $html .= "<div style='display:block'> <input type='text' name='$row->user_id' id= '$row->user_id' value='$row->user_id' />  </div>"; return $html; It will return all the values from the users table.

Input field for search

For hidding while OnFocus Search input field, we can use simple Javascript inside the field, <input type="text" name="s" id="searchinput" value="Search here ..." onblur="if (this.value == '') {this.value = 'Search here ...';}" onfocus="if (this.value == 'Search here ...') {this.value = '';}">

Solution for getting error in less than IE9 does not support querySelectorAll

You have to include the below lines, Quirks mode: this is usually triggered by a missing or broken Doctype. If this is the case, make sure your page starts with the following: <!DOCTYPE html> Compatibility mode (IE7 mode): This may be triggered if you're viewing the page locally (ie running it on your local machine, eg for testing, or on your local network). In this case, you are being hit by an IE config setting that you should disable. Go to the Tools menu, and pick the Comaptibility View Settings option. Untick the compatibility options, and the page should start working. Compat mode may also be triggered (or avoided) by an X-UA-Compatibility meta tag. If you're having trouble with compatibility mode, this is a good way to avoid it: Add the following line to your code: <meta http-equiv="X-UA-Compatible" content="IE=edge">  Src: http://stackoverflow.com/questions/16920365/ie8-does-not-support-queryselectorall

Accurate time using PHP

<?php     function ezDate($d) {         $ts = time() - strtotime(str_replace("-","/",$d));                 if($ts>31536000) $val = round($ts/31536000,0).' year';         else if($ts>2419200) $val = round($ts/2419200,0).' month';         else if($ts>604800) $val = round($ts/604800,0).' week';         else if($ts>86400) $val = round($ts/86400,0).' day';         else if($ts>3600) $val = round($ts/3600,0).' hour';         else if($ts>60) $val = round($ts/60,0).' minute';         else $val = $ts.' second';                 if($val>1) $val .= 's';   ...

Date/Time in PHP

<?PHP      //Current Year     $year = date("Y");      //2013         //Current Month     $month = date("m");    //08         //Current day     $day = date("d");     //12         //Tomorrow's day     $day = date("d")+1;    //13             //TODAY'S DATE          $start =  date("Y-m-d");     //2013-08-12               //1 MONTH FROM TODAY          $end = date("Y-m-d",strtotime("+1 months"));     //2013-09-12          //5 DAYS FROM TODAY         $reminder = date("Y-m-d",strtotime("+5...

Birthdate validation for less than 18 in PHP

Here is the code to validate for birthdate, //Validate for users below 18 only function birthdate($then, $min) {   // $then will first be a string-date   $then = strtotime($then);   //The age to be less than 18   $min = strtotime('+18 years', $then);    if(time() < $min)   {      return false;   }   else {      return true;   } }

ul li for 4 partition

Code:    {assign var="productByLine" value = "4"}    {assign var="productLineTurn" value = "1"}    {assign var="tr" value = "true"}    {assign var="turns" value = "1"}        <table style="border: 1px solid #CCC;">       {foreach from=$upcomingEvent item=product name=products}                    <!-- Start a new line -->          {if $tr eq "true"}             <tr>             {assign var="productLineTurn" value = "1"}             {assign var="tr" value = "false"}          {/if}              ...

Facebook - Sharing with site image, title and description

Facebook crawls the page to decide how to display it. In order to specify the share to look according to your liking, you will have to add open graph tags . Below is the example: <meta property="og:image" content="URL OF IMAGE" /> <meta property="og:title" content="TITLE TO APPEAR" /> in the header of each page of your site. You can know about it from here: http://support.sharethis.com/customer/portal/articles/475079-share-properties-and-sharing-custom-information#Open_Graph_Tags Please remove the "st" properties from the span tag code, the span tag should look like - Hello User, <span class='st_facebook_large' ></span>

Javascript: Textarea should replace break on enter

Use this code to  get break as user enters in the textarea. Hope this helps! <html> <head> <title>Insert new lines dynamically</title> <script type = "text/javascript">  function fillTarg() {  var TARG = document.getElementById("newtext")  var AREA = document.getElementById("textarea")   TARG.innerHTML = AREA.value.replace(/\n/g,"<br>") // Replace break on user enters  TARG.innerHTML = AREA.value.replace(/\s/g,"&nbsp;")  // Replace space on user enters } </script> </head>   <body> <textarea style="width:450px; height:150px;" id="textarea"  onKeyUp="fillTarg()">Click on the button below to add some lines!</textarea> <br><br> <span id="newtext"> </span> </body> </html>

Javascript - Color box using URL or iframe

We have to use this script where the output will take from url, Javascript: ======== <script> function getParameterByName(url, name) {   name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");   var regexS = "[\\?&]"+name+"=([^&#]*)";   var regex = new RegExp( regexS );   var results = regex.exec(url);   if( results == null )     return "";   else     return decodeURIComponent(results[1].replace(/\+/g, " ")); } $(document).ready(function(){ $('.dialog-open').each(function() {    $(this).colorbox({      height: 600,      width: 800,      iframe: true,      href: "contact?id=" + getParameterByName($(this).attr("href"), "id")    }); }); </script> HTML ===== <a href='test.php?id=$id' class="dialog-open"> test </a>    Source: http://www.jacklmoore.com/colorbox/

PHP / Smarty Tricks - Avoid looping for more than one loop for select query

The best way is we can use " IN_ARRAY " method, Here is the basic sample i have given, {assign var = "exp" value = ","|explode:$catid}   {section name=k loop=$blogcat}    <option {if in_array($blogcat[k].CAT_ID, $exp)} selected="selected"  {/if}  value="  {$blogcat[k]. CAT_ID }"  >{$blogcat[k].CAT_NAME}    </option>                                                         {/section}

PHP - Mysql - Apostrophe issue

The best solutions is to use: mysql_real_escape_string() Eg: INSERT INTO <t.name> ("content") VALUES (mysql_real_escape_string("There's a dummy content here"));   If you still facing issue, the best way is to use,   addslashes(mysql_real_escape_string()) Eg: INSERT INTO <t.name> ("content") VALUES (addslashes(mysql_real_escape_string("There's a dummy content here")));  

Dreamweaver 8 - Serial number

WPD800-53539-13932-17521

Joomla - Get user id

To get user id in joomla use, $user =& JFactory::getUser(); $userId = $user->get( 'id' ); You can also get User details like, $user =& JFactory::getUser(); $userId = $user->username;   // Returns username $userId = $user->name;         // Returns real name $userId = $user->id;             // Returns id

FTP- 503 user cannot login home directory inaccessible - Godaddy

If you find this error in FTP. Please first check whether you have provided correct host name. Sometimes the host name might be in IP address . In that case try with this,   ftp.YourDomain.com

Smarty - How to check smarty Version

In template file you have to give, {$smarty.version} Output: Smarty-3.1.8

Javascript - To get URLs in JS

This function is used to get values from URL. function getUrlVars() {     var vars = {};     var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {         vars[key] = value;     });     return vars; } Eg: URL: http://www.xyz.com?type=test Output:   test So that we can check through Javascript, var type = getUrlVars()["type"]; if(type == "test") { alert(" I am here"); }