List Box Manipulation using jQuery

Working on listbox I assume that jquery is very simple to move data from one list box to another. Yes I implemented it.
Here I implemented on submit button and on double click on object. To implement this first include jquery to simple html page

<script type="text/javascript" src="jquery.js" charset="utf-8"></script>

Suppose you have two list boxes in an html table having some values and two button to move data from listbox first to another a list box and two buttons are like:

<select id="firstList" multiple="multiple" style="height:420px;width: 250px;" >
<option value="1">PHP</option>
<option value="2">.Net</option>
<option value="4">Paste</option>
<option value="5">Pea</option>
<option value="6">Pamp</option>
<input id="to2" type="button" name="to2"  title='assign' value=">" /><br/><br/>
<input id="to1" type="button" name="to1" title='unassign' value="<">
<select id="secondList" multiple="multiple" style="height:420px;width: 250px;" ></select>

All is the game of jquery functioning how we can obtained to move data from one list box to another.
Create two functions in assignList and unassignList like

// function: UnAssignment
function assignList()
// loop through first listbox and append to second listbox
$('#firstList :selected').each(function(i, selected){
// append to second list box
$('#secondList').append('<option value="'+selected.value+'">'+ selected.text+'</option>');
// remove from first list box
$("#firstList option[value='"+ selected.value +"']").remove();
// function: UnAssignment
function unassignList()
// loop through second listbox and append to first listbox
$('#secondList :selected').each(function(i, selected){
// append to first list box
$('#firstList').append('<option value="'+selected.value+'">'+ selected.text+'</option>');
// remove from second list box
$("#secondList option[value='"+ selected.value +"']").remove();

To make this functioning add jquery button and double click event to button and object itself.

$('#firstList').dblclick(function() {

$('#secondList').dblclick(function() {



As we now one important thing to notice if list box is full of values and we have to search any particular value so it is difficult to search whole list box, for searching through list box take a text box and below how this function searchFirstList filter
No for this I have a textbox to filter
<input id=”firstFilterSearch” type=”text”>

// Function for Filtering
function searchFirstList(inputVal, searchArea)
var allCells = $(searchArea).find(‘option’);
if(allCells.length > 0)
var found = false;
allCells.each(function(index, option)
var regExp = new RegExp(inputVal, ‘i’);

Calling this function

var searchArea = $('#firstList'); // Select Box ID
searchFirstList($(this).val(), searchArea);

Here is example EXAMPLE

XML Parsing With PHP And jQuery…Continued

As in my previous post I gave an idea of Xml and its parsing, In continuation with the last post here I will try to explain how XML and JQuery works.

When an AJAX request is sent to the server, we receive a response from server it may be either success or a failure. In case of success we get data in Xml or other format. In case of XML we can parse it by Jquery.
For Example: We posted an AJAX request to fetch all records of employees from database and display on page.

 type: “POST”,  //type of request  GET or POST
 url: emp_detail.php, // url to which the request is send
 success: function(xmlData){// function to be called if the request succeeds
 funEmpData(xmlData); // return data
 error: function(){  //function to be called if the request fail


This Ajax request retrieve all detail of employee, I use Mysql and PHP to get it. Let we have a database table having columns user_id, username and address.  In file ‘emp_detail.php’ we retrieve data and create Xml.

// Connection to MySql
$conn = mysql_connect('localhost','root','');
// Selecting Database
$sql = "select * from emp";
$results = mysql_query($sql);
$count = 0;
$return_data = '';
// Creating xml
while ( $row = mysql_fetch_assoc($results))
 $xml_node      .= "<emp_data>\n";
 $xml_node     .= "<userid>" . $row['user_id'] . "</userid>\n";
 $xml_node     .= "<username>" .$row['username'] . "</username>\n";
 $xml_node     .= "<address>" . $row['address'] . "</address>\n";
 $xml_node     .= "</emp_data>\n";

$returnXML = "<?xml version='1.0' encoding='UTF-8'?>\n".$xml_node;

echo $returnXML;

Above code give Xml when Ajax request is processed and create  ‘emp_data’ as a parent node and userid, username and address as a child node

<?xml version='1.0' encoding='UTF-8'?>

We get this Xml in success of an Ajax request in variable ‘xmlData’, and to parse this Xml we create a function funEmpData.

function funEmpData(xmlData)
 // all raw data is in returnXML
 // itertin through loop in jQuery
 var table_data = '<table border=1 ><tr><td>User Name</td><td>Address</td>';

 var username    = $(this).find('username').text();
 var address     = $(this).find('address').text();
 table_data += '<tr >';
 table_data += '<td>'+username+'</td>';
 table_data += '<td>'+address+'</td></tr>';


 table_data += '</table>';

 $('#emp_search_data').html(table_data); // for display


In above function, to display employee detail we embedded data in Html table structure. Looping through Xml,  Jquery first find parent node and get all nodes one by one and all data is embed in Html table and at the end display that data in DIV having id  ‘emp_search_data’.

Working with PHP and XML

This article gives you an understanding that how can we read a XML Document in PHP.
first we have an idea that what is XML? Xml is a data storage format. It makes a choice for user to define tags and attributes. A simple structure of an xml document is:

<?xml  version="1.0" ?>
<?xml  version="1.0" ?>
  <employee name=”abc” salary=”10000” />

In this xml document parent tag is and its child tags , which has a set of information and tags. And in second example we can use attributes to an xml tags as key/value pair. Now to parse this xml document php has a SimpleXML extension tool.

// storing xml as a string variable
$xml_string = "<?xml  version='1.0' ?>
$xmlObj = simplexml_load_string($xml_string);

simplexml_load_string() is a php function for parsing XML Document. From this xml object $xmlObj we can get employee name and salary

$name = $xmlObj->employee->name;
$salary = $xmlObj->employee->salary;
echo "Name is:".$name."<br /> Salary is:".$salary;
// OR
//If we want data from attributes use:
foreach($xmlObj->employee[0]->attributes() as $key => $value)
    echo $key,'="',$value,"\"\n";

In this example $a print attribute name”abc” $b its value “10000”. This is a simple description how php interacts with xml. Last there are some illegal XML characters that cannot be parsed by xml are: [<, > &, ‘, “]. So keep in mind when creating xml document.

PHP Command Line Scripting

PHP is one of the open source language widely used to develop web applications. Most of web developers knows but many of us are unaware of PHP command line script. There are many other mundane tasks that can be only possible in the background on web server. Here comes the importance that why we use php in CLI mode, like cron jobs or time consuming task as taking daily backups of files or running such scripts that can run as they can until the web server shutdown.

This article describes how php interacts with CLI (Command Line Interpreter) and run the php program.
In my previous post I gave you a basic knowledge of how to run php in command prompt. No problem if you forgot. simply add the php bin directory to environment variable:
Open computer properties advance options there is PATH variable.
To execute php on CLI (Command Line Interpreter) mode, add php to environment variable
as  ;C:/wamp/bin/php/php5.2.8/bin
Now Reboot the System to set all environment variables.
To test PHP is working on CLI type the following command in prompt

C:/>php  –v  //Gives PHP version
PHP 4.3.6 (cli) (built: Apr 19 2004 10:02:14)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
To get more help use the switch –h, like
C:/> php -h

Now create a new file named as cli.php and type this program

 print "PHP CLI World!";

You can execute this script by typing:
C:/>php phpcli.php
It display
PHP CLI World!
In command line we cannot render HTML tags, like to insert new line we have to use “\n” instead of “<br>”.

echo "Hello CLI<br>How are You?\n Welcome 2010.";

it display
Hello CLI<br>How are You?  //<br> is as it is printed.
Welcome 2010. // this is in new line

We can also access command line arguments by using $argc, $arg variable or $_SERVER[‘argc’], $_SERVER[‘argv’], access these arguments create a php file and type these lines

echo "argc values: ".$argc;
echo "\n argv values:".$argv[1];

Now in command line run this script. Suppose you have create a file name argtest.php then type
C:/>php argtest.php testarg
We will get

argc values: 2
argv values:testarg

$argc give the number arguments enter including.  $argv is an array of arguments. As you can see file name itself is at index 0 and you can get by $argv[0].
Now lets have a basic idea of Input/output Stream in PHP. There are three IO streams in php.
These streams are defined as constants namely STDIN, STDOUT AND STDERR from PHP 4.3.0+ CLI version.
Now instead of using print or echo for output, we can use the standard output stream defined in CLI version of the PHP.
For an example..

fwrite(STDOUT, "Enter Name:\n");
$name = fgets(STDIN);
fwrite(STDOUT, "Happy Morning $name");

In this example it asks for input, suppose you have entered “Sah”. It save it in $name variable, which is output as “Happy Morning Sah”The third stream STDERR is used to separate the error message from normal output and use as

fwrite(STDERR, "ERROR");

So these are the basics that how php interacts with command line scripting and hope PHP GUI developers now have an idea of PHP when run on terminal is more powerful language than other languages.

nike tn pas cher tn pas cher peuterey outlet piumini peuterey outlet spaccio peuterey outlet peuterey outlet piumini peuterey outlet spaccio peuterey outlet hogan outlet scarpe hogan outlet hogan outlet online peuterey outlet piumini peuterey outlet spaccio peuterey outlet hogan outlet scarpe hogan outlet hogan outlet online hogan outlet scarpe hogan outlet hogan outlet online doudoune moncler pas cher moncler pas cher doudoune moncler hogan outlet scarpe hogan outlet hogan outlet online nike tn pas cher tn pas cher