service network restart
All posts by Pramod T P
Dynamically Add/Remove Any number of Textboxes
<?php $max_no_boxes=10; ?>
<script type="text/javascript">
function addnames() {
document.getElementById("totalnames").value =
Number(document.getElementById("totalnames").value) + Number(1);
if(Number(document.getElementById("totalnames").value)>=
Number(<?php echo $max_no_boxes ?>)){
document.getElementById("totalnames").value=<?php echo $max_no_boxes ?>;
document.getElementById("nameButton").style.display="none";
}
document.getElementById("name"+document.getElementById("totalnames").value)
.style.display="block";
}
function removenames() {
document.getElementById("name"+document.getElementById("totalnames").
value).style.display="none";
document.getElementById("totalnames").value =
Number(document.getElementById("totalnames").value) - Number(1);
if(Number(document.getElementById("totalnames").value)<
Number(<?php echo $max_no_boxes ?>))
document.getElementById("nameButton").style.display="block";
}
</script>
<table>
<tr>
<td valign="top">Name</td>
<td valign="top">
<div class="project_right">
<?php for($i=2;$i<=$max_no_boxes;$i++) { $nameValue = "name".$i; ?>
<div style="display:<?php echo $totalnames>= $i ?"block":"none"; ?>"
id="name<?= $i ?>">
: <input type="text" name="name<?= $i ?>" class="projectText"
value="<?php echo $$nameValue ?>">
<a href="javascript:return false;" onClick="javascript:removenames();">Remove</a>
</div>
<?php } ?>
<div style="width:175px;; clear: left; float:left">:
<input type="text" name="name1" class="projectText"
value="<?php echo $name1 ; ?>">
</div>
<div style="width:20px; clear: none; float:left">
<a id="nameButton" href="javascript:return false;"
onClick="javascript:addnames();">Add</a>
</div>
<input type="hidden" id="totalnames" name="totalnames"
value="<?php echo $totalnames==""?1:$totalnames; ?>" />
</div>
</td>
</tr>
</table>
Submit HTML form to pop up page
<script language="JavaScript" type="text/JavaScript">
function MM_reloadPage(init) {
if (init==true) with (navigator) {
if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight;
onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW ||
innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
function popupWindow(pageURL,WindowName,features) { //v2.0
window.open(pageURL,WindowName,features);
}
</script>
<form method="post" action="test.php" target="list"
onSubmit="popupWindow('test.php','list','scrollbars=yes,width=500, height=400')">
<input type="text" name="name">
<input type="submit" value="Submit" name="submit">
</form>
Fetch an element from the array randomly – PHP
<?php
$testArray = array("value1", "value2", "value3", "value4");
$testRand = array_rand($testArray, 2);
echo $testArray[$testRand[0]];
?>
Sort the element of an array in reverse order – PHP
<?php
$testArray = array("p", "c", "z", "a");
rsort($testArray);
print_r($testArray);
//Array ( [0] => z [1] => p [2] => c [3] => a )
?>
Sort the element in an array – PHP
<?php
$testArray = array("p", "c", "z", "a");
sort($testArray);
print_r($testArray);
//Array ( [0] => a [1] => c [2] => p [3] => z )
?>
Function to add an element into an array – PHP
<?php
$testArray = array("value1", "value2");
array_push($testArray, "value3", "value4");
print_r($testArray);
//rray ( [0] => value1 [1] => value2 [2] => value3 [3] => value4 )
?>
Search an element in an array and return the key – PHP
<?php
$testArray = array(0 => 'value1', 1 => 'value4', 2 => 'value2', 3 => 'value3');
$key = array_search('value2', $testArray); // $key = 2;
echo "Key is ".$key ; // 2
?>
Find out the product of elements in an array – PHP
<?php $testArray = array(3, 2, 4, 7); echo "product is " . array_product($testArray); // product is 168 ?>
Function to replace array elements – PHP
<?php
$testArray = array("orange", "banana", "apple", "raspberry");
$replaceArr1 = array(0 => "pineapple", 3 => "cherry");
$replaceArr2 = array(0 => "grape");
$basket = array_replace($testArray, $replaceArr1, $replaceArr2);
print_r($basket);
//Array ( [0] => grape [1] => banana [2] => apple [3] => cherry )
?>