Monday, March 31, 2014

select and unselect all checkbox by javascript




<div class="mt10">

<a href="javascript:;" class="c068 bline" onclick="getCheckedBoxes('check[]',1)">Select all</a>&nbsp;&nbsp;&nbsp;&nbsp;

<a href="javascript:;" class="c068 bline" onclick="getCheckedBoxes('check[]',2)">Select none</a>&nbsp;&nbsp;&nbsp;&nbsp;

<a href="javascript:;" class="c068 bline" onclick="return deletfavorite();">Delete selected</a>

<!-- <form name="searchForm" action="" method="post">
<input id="key" name="search" style="width:200px" value="" class="input1" type="text">
<input type="submit" name="submit" value="Search">
</form> -->
</div>
<form name="list" method="post" action="">
<p>
<input name="check[]" type="checkbox" value="11">c1
</p>
<p>
<input name="check[]" type="checkbox" value="11">c2
</p>
<p>
<input name="check[]" type="checkbox" value="11">c3
</p>
<p>
<input name="check[]" type="checkbox" value="11">c4
</p>
</form>


<script>

 jQuery('#mydesign').attr('class','active');

function getCheckedBoxes(chkboxName,val) {

 var checkboxes = document.getElementsByName(chkboxName);

 var checkboxesChecked = [];

 // loop over them all

   for (var i=0; i<checkboxes.length; i++) {

// And stick the checked ones onto an array...

if(val==1){

checkboxes[i].checked='checked';

}

 if(val==2){

  checkboxes[i].checked='';

 }



 }



}





function deletfavorite(){

var checkboxes = document.getElementsByName('check[]');

$check=false;

for (var i=0; i<checkboxes.length; i++) {

if(checkboxes[i].checked){

$check=true;

break;

}



}



if($check){

var r=confirm("Conform to Delete!")

if (r==true){

document.list.submit();

}else{

return false;

}



}else{

alert('Check At list One Option!');

}



}





</script>

Wednesday, March 12, 2014

Creating Thumbnails with PHP using the GD Library

<?php
function getBaseResizeImage($sourceImgPath,$destinatioImgPath,$resizePercentage,$extensiontoConvert=''){
/*
* PHP GD
* resize an image using GD library
*/

// File and new size
//the original image
$filename=file_get_contents($sourceImgPath);
$filename2 = $sourceImgPath;


if($extensiontoConvert==''):
$ext = pathinfo($filename2, PATHINFO_EXTENSION);
else:
$ext=$extensiontoConvert;
endif;

//the resize will be a percent of the original size
$percent = $resizePercentage;

// Content type
header('Content-Type: image/jpeg');
header('Content-Type: image/png');
 

// Get new sizes
list($width, $height) = getimagesize($filename2);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth,$newheight);
$source = imagecreatefromstring($filename);

// Resize
imagecopyresized($thumb,$source,0,0,0,0,$newwidth,$newheight,$width,$height);

// Output and free memory
//the resized image will
if($ext=='jpg'):
$destPath=$destinatioImgPath;
imagejpeg($thumb,$destPath);
endif;
if($ext=='png'):
$destPath=$destinatioImgPath;
imagepng($thumb,$destPath);
endif;
//imagedestroy($thumb);
}
$sourceImgPath='2879.jpg';
$destinatioImgPath='ram.png';
$resizePercentage='0.5';
$extensiontoConvert='png';
getBaseResizeImage($sourceImgPath,$destinatioImgPath,$resizePercentage,$extensiontoConvert);
?>

resize image and change type by GD livery in php

<?php

function getBaseResizeImage($sourceImgPath,$destinatioImgPath,$resizePercentage,$extensiontoConvert=''){
/*
* PHP GD
* resize an image using GD library
*/

// File and new size
//the original image
$filename=file_get_contents($sourceImgPath);
$filename2 = $sourceImgPath;


if($extensiontoConvert==''):
$ext = pathinfo($filename2, PATHINFO_EXTENSION);
else:
$ext=$extensiontoConvert;
endif;

//the resize will be a percent of the original size
$percent = $resizePercentage;

// Content type
header('Content-Type: image/jpeg');
header('Content-Type: image/png');
 

// Get new sizes
list($width, $height) = getimagesize($filename2);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth,$newheight);
$source = imagecreatefromstring($filename);

// Resize
imagecopyresized($thumb,$source,0,0,0,0,$newwidth,$newheight,$width,$height);

// Output and free memory
//the resized image will
if($ext=='jpg'):
$destPath=$destinatioImgPath;
imagejpeg($thumb,$destPath);
endif;
if($ext=='png'):
$destPath=$destinatioImgPath;
imagepng($thumb,$destPath);
endif;
//imagedestroy($thumb);
}
$sourceImgPath='2879.jpg';
$destinatioImgPath='ram.png';
$resizePercentage='0.5';
$extensiontoConvert='png';
getBaseResizeImage($sourceImgPath,$destinatioImgPath,$resizePercentage,$extensiontoConvert);
?>

Tuesday, March 11, 2014

add remove text box by javascript

<div id="content" class="add-images">
                    <div><ul><li>Label</li><li>Width</li><li>X</li><li>Height</li></div>
                    <div class="add-fil">
                   
                    <input name="label[]" type="text">
                    <input name="width[]" type="text">X
                    <input name="height[]" type="text">
                   
                    </div>
                    <div style="float:left;">
                        <input name=""  class="btn-all" type="button" value=" + " onclick="addInputFile()">
                        <input name="" class="btn-all" type="button" value=" - " onclick="removeElement()">
                        <input id="uploadButton" style="margin-top:8px;" class="" name="uploadButton"  type="submit" value="Submit My Work">
                    </div>
                </div>
               
                <script type="text/javascript">
            var intTextBox=0;
            //FUNCTION TO ADD TEXT BOX ELEMENT
            function addInputFile()
            {
                intTextBox = intTextBox + 1;
                var contentID = document.getElementById('content');
                var newTBDiv = document.createElement('div');
                newTBDiv.setAttribute('id','strText'+intTextBox);
                newTBDiv.setAttribute('class','strText');
                newTBDiv.innerHTML = "<input name='label[]' type='text'><input name='width[]' type='test'>X<input name='height[]' type='text' id='" + intTextBox + "' >";
                contentID.appendChild(newTBDiv);
            }
            //FUNCTION TO REMOVE TEXT BOX ELEMENT
            function removeElement()
            {
                if(intTextBox != 0)
                {
                    var contentID = document.getElementById('content');
                    contentID.removeChild(document.getElementById('strText'+intTextBox));
                    intTextBox = intTextBox-1;
                }
            }
        </script>