Archive

Archive for June, 2007

Client-side Table Sorting Using Javascript

Jun 30th, 2007

Sort column/field data in ascending / descending order while maintaining row data with the help of JavaScript only. So, no server-side script and no page refresh.

Select all from textarea/ text input on onclick event

Jun 17th, 2007

Here when an user click on a text link “select all”, all the contents of the textarea will be highlighted. You can use onclick event directly on textarea also.

<script type=”text/javascript”>

function select_all(element1) {
// first set focus
document.frm1.elements[element1].focus();
// select all contents
document.frm1.elements[element1].select();
}
</script>

<form name=”frm1″>
<a href=”#” onclick=”select_all(‘desc’)”>Select all</a>
<textarea name=”desc” cols=”50″ rows=”7″></textarea>
</form>

Javascript show hide div, p, input or any HTML elements

Jun 17th, 2007

JavaScript show hide code hiding and showing any elements including popular div, p. Good toggle view functionality that consider input values when you hide it.

Check and Remove Duplicate Values from PHP Array

Jun 17th, 2007

PHP code for directly removing duplicate entry in Array and also test only script to check duplicate value in array

PHP array – Common Usage

Jun 17th, 2007

You will use “print_r” and “foreach” many times during programming at the time of using array.

<?php
$arr3 = array(‘a’, ‘b’, ‘c’, ‘d’);

echo ‘<pre>’;
print_r($arr2);
echo ‘</pre>’;
?>

print_r() will print whole array with key=>value pair in human readable format.
Delete every item, but not array

foreach ($arr3 as $key=>$value) {
unset($arr3[$key]);
}
foreach is specifically made for array. It provides an easy way to traverse [...]

Array in PHP

Jun 17th, 2007

Array Syntax:
array ([key=>] value,)
Key may be an integer or string, and value may be any value.
<?php

$arr1 = array (‘lang’=>’php’, 1=>true, 13);

echo $arr1['lang'] ; // print php
echo $arr1[1]; // 1
echo $arr1[2]; // 13
?>
As you can see above string ‘key’ is quoted.
An array [...]