Jquery function to get the selected check box values

The following code will get the selected checkbox values using jquery. var selected = new Array(); $(‘input[name=postcheckbox]:checked’).each(function() { var val = $(this).val(); selected.push(val); }); console.log(selected); Where ‘postcheckbox’ is the name of the checkbox as follows. <input type=”checkbox” name=”postcheckbox” value=”1″ > <input type=”checkbox” name=”postcheckbox” value=”2″ > <input type=”checkbox” name=”postcheckbox” value=”3″ > It will write the checkbox [...]

Jquery function to check all/ uncheck checkboxes

The following jquery code will work for check all/ un check check boxes $(‘#chkallposts’).live(‘click’,(function(){ if($(this).is(‘:checked’)) $(‘.chkposts’).attr(“checked”,true); else $(‘.chkposts’).attr(“checked”,false); })); where ‘#chkallposts’ is the id of main check box and ‘.chkposts’ is the class name of sub checkboxes

Code to get file data based on new line

The following code will help to get the data from a text file. <?php $fh = fopen(‘comments.txt’,’r’); $i=1; while ($line = fgets($fh)) { echo $line.’<br>’; } fclose($fh); ?>

Category: PHP

Function to validate an rss feed using php

The following code will validate an rss feed. It will return true/false based on the rss feed <?php function validateFeed( $sFeedURL ) { $sValidator = ‘http://feedvalidator.org/check.cgi?url=’; if( $sValidationResponse = @file_get_contents($sValidator . urlencode($sFeedURL)) ) { if( stristr( $sValidationResponse , ‘This is a valid RSS feed’ ) !== false ) return true; else return false; } else [...]

Category: PHP

Select text in a div on click

The following code gives the option to select text in a DIV. <script type=”text/javascript”> $(document).ready(function() { jQuery.fn.selectText = function(){ var doc = document; var element = this[0]; console.log(this, element); if (doc.body.createTextRange) { var range = document.body.createTextRange(); range.moveToElementText(element); range.select(); } else if (window.getSelection) { var selection = window.getSelection(); var range = document.createRange(); range.selectNodeContents(element); selection.removeAllRanges(); selection.addRange(range); } [...]

Print preview using javascript

Using javascript we can create printer friendly webpages.We can use window.print function to print a webpage. The script is as follows. <a href=”javascript:window.print()”>Click to Print This Page</a> When we click on the print button a print dialog window will open and we can either print the page or can cancel the print. Using this method [...]

Ajax + PHP sample code

Function to create ajax object AJAX stands for Asynchronous JavaScript and XML. Ajax is a technology used to refresh a page content(or page area ) with out refreshing the whole page.AJAX is based on JavaScript and HTTP requests.We can use multiple ajax requestes on same page. In the following example we are going to print [...]

Simple Encryption in PHP

Encryption using php A text or a password encryption can be done very easily using the functions md5() or sha1() or crypt() in php. It’s a basic need to protect the password. The first step towards it is to encrypt it. Text Encryption Using MD5 ( RSA’s MD5 Message-Digest Algorithm ): Example: Original Text – [...]

Category: PHP

Finding Database Size using php & mysql

The dbsize of mysql can be retrieved using the query “show table status’. Follow the steps to find the DB size Step 1: Getting connection with the databse <?php $db = mysql_connect(“hostname”, “username”,”password”); //getting the mysql db connection by passing correct hostname,username and passowrd mysql_select_db(“dbname”,$db); //there we pass the db name for which we want [...]

How to parse XML data using PHP

Parse XML data using PHP XML stands for eXtensible Markup Language and is used primarily for data storage and organization. It is useful for many things but the main thing about it is that there are no predefined tags.If we want to parse an XML data to use, we need to convert that data for [...]

Category: PHP