-
Links
-
Recent Posts
Categories
Category Archives: javascript
Working with select
We have the html code below: <select name="sel" id="sel"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> Code below set the current value
Posted in javascript
Leave a comment
How to select option when page is loaded
<html> <head> <script type=”text/javascript”> function load() { document.getElementById(‘select_id’).value = 24; } </script> </head> <body onload=”load()”> <h1>Hello World!</h1> </body> </html>
Include JQuery UI framework from Google libs
Code snippet to include JQuery UI framework from Google libs <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> </head>
Posted in javascript, javascript snippets, jquery, jquery snippets
Tagged include JQuery UI framework
Leave a comment
Javascript function to round number to 2 decimal places
function roundNumber(num, dec) { var result = String(Math.round(num*Math.pow(10,dec))/Math.pow(10,dec)); if(result.indexOf(‘.’)<0) {result+= ‘.’;} while(result.length- result.indexOf(‘.’)<=dec) {result+= ’0′;} return result; }
Javascript function to get curent date
Here is the implementation of javascript function returning the current date in dd-mmm-yyyy format function getCurDate(){ var months = new Array(“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”, “Des”); var myDate = new Date(); return myDate.getDate() + … Continue reading
Posted in javascript, javascript snippets
Tagged javascript function to get current date
Leave a comment
Javascript: how to detect if variable is defined
if( “undefined” === typeof data ) alert(‘data is not defined); else alert(‘data is not defined’);
How to send the variable from php to html page
<script type="text/javascript"> $(document).ready(function(){ var s=location.hash; var arr=s.split('-'); if( arr[1] ) alert( "Please enter the " + arr[1] );
Posted in javascript, php
Leave a comment
Javascript: how to use history back() method
<html> <head> <script type="text/javascript"> function goBack() { window.history.back() } </script> </head> <body> <input type="button" value="Back" onclick="goBack()" /> </body> </html>
Posted in javascript, javascript snippets
Leave a comment
How to implode array in JavaScript
var arrayName = new Array(); arrayName.join(‘delimiter’);
Javascript: How to resize the image to content width
<script> $('#article_page_{$article_id}').live( 'pagecreate',function(event) { var my_w=$('#article_page_{$article_id}').width() – 40; $('.article_text img').each( function(){ $(this).css('width', ($(this).width() > my_w?$(this).width():my_w) +'px'); }); }); </script>";
Posted in javascript, javascript snippets, jquery
Leave a comment