Wednesday, March 28, 2012

get key code in javascript




<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script language="javascript">

function keyCode(evt,x)
 {

         var charCode = (evt.which) ? evt.which : event.keyCode ; alert(charCode);
}

</script>
<input type="text" onkeyup="return keyCode(event , this)"  />

get File Extention name in php and javascript

// php
 $ext = substr(strrchr($fileName, '.'), 1);


// javascript
var file = $('#txtfile').val();
ext = file.substr(file.lastIndexOf('.')+1);
alert(ext);






Tuesday, March 20, 2012

check uncheck all check box using javascript and jquery


Your ckname are
name 1
name 2
name 3
name 4
name 5
name 6

Select / Unselect All



<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script language="javascript">


function selectallCHBox(){



if($('#selectall').attr('checked')){
var inputs = document.getElementsByClassName('chechid');
var checkboxes = [];
for (var i = 0; i < inputs.length; i++) {

  if (inputs[i].type == 'checkbox') {
inputs[i].checked =true; } }
}
else {
var inputs = document.getElementsByClassName('chechid');
var checkboxes = [];
for (var i = 0; i < inputs.length; i++) {

  if (inputs[i].type == 'checkbox') {
inputs[i].checked =false; } }

}

}

</script>
</head>
<body>
<form name="form1" onSubmit="return validate()">
Your ckname are <br>
<input type="checkbox" name="ckname[]" class="chechid" value="blue" id="blue"> name 1 <br>
<input type="checkbox" name="ckname[]" class="chechid"  value="red" id="red">name 2 <br>
<input type="checkbox" name="ckname[]" class="chechid"  value="green" id="green">name 3 <br>
<input type="checkbox" name="ckname[]" class="chechid"  value="yellow" id="yellow">name 4 <br>
<input type="checkbox" name="ckname[]" class="chechid"  value="voilet" id="voilet">name 5 <br>
<input type="checkbox" name="ckname[]" class="chechid"  value="grey" id="grey">name 6 <br>
<br>
<input type="checkbox" name="selectall"  id="selectall" onClick="selectallCHBox();" />Select / Unselect All
</form>
</body>
</html>

Add Bcc and CC in email on php



 if($cc!="")
echo $headers .= "\r\nCc: ".$cc;
 if($cc!="")
$headers .= "\r\nCc: ".$cc;
if($bcc!="")
$headers .= "\r\nBcc: ".$bcc."\r\n\r\n";

Check Box Validation In javascript


Your ckname are
name 1
name 2
name 3
name 4
name 5
name 6





<html>
<head>
<script language="javascript">
function validate()
{
var chksob = document.getElementsByName('ckname[]');
var checkchecked = false;
for (var i = 0; i < chksob.length; i++)
{
if (chksob[i].checked)
{
checkchecked = true;
break;
}
}
if (checkchecked == false)
{
alert("Please select at least one Name .");
return false;
}
return true;
}
</script>
</head>
<body>
<form name="form1" onSubmit="return validate()">
Your ckname are <br>
<input type="checkbox" name="ckname[]" value="blue" id="blue"> name 1 <br>
<input type="checkbox" name="ckname[]" value="red" id="red">name 2 <br>
<input type="checkbox" name="ckname[]" value="green" id="green">name 3 <br>
<input type="checkbox" name="ckname[]" value="yellow" id="yellow">name 4 <br>
<input type="checkbox" name="ckname[]" value="voilet" id="voilet">name 5 <br>
<input type="checkbox" name="ckname[]" value="grey" id="grey">name 6 <br>
<br>
<input type="submit" value="submit" name="submit"/>
</form>
</body>
</html>

Monday, March 19, 2012

select radio button using jquery

checked radio button using jquery

('#idOfRadio').attr("checked","checked");
<input type="radio" id="idOfRadio" name="idOfRadio" />

Saturday, March 17, 2012

PHP Script for sending mail with attachment file

send email with attachment in php 


code to send email with attachment in php 


form.html



<form action="sendmail.php" >
<label> Name:</label>
<input type="text" name="name" id="name" />
<label> email:</label>
<input type="text" name="email" id="email" />
<label> Phone No:</label>
<input type="text" name="ph" id="ph" />
<label> Message:</label>
<input type="text" name="msg" id="msg" />
<label> Resume :</label>
<input type="file" name="txtresume" id="txtresume" />
<input type="submit" name="send mail" value="send mail"  />
</form>




sendmail.php


<?php
error_reporting
(0);

//ini_set('display_errors','off');
//ini_set('memory_limit', '-1');


 
if(isset($_POST) && !empty ($_POST["name"]) ){
$files = array($_FILES["txtresume"]["tmp_name"]); 

// txtresume input type = file name =txtresume
 
$files1 = array($_FILES["txtresume"]["name"]);

$name $_POST['name']; 

$email $_POST['email']; 
$ph $_POST['ph'];
$msg $_POST['msg']; 
$subject " Resume ";
 
$message1 "Name: " $name "<br> Phone No: " $ph"<br/>Email Id:".$email "<br/>Message Details : " $msg  ;

 
$headers "From: $email";
// boundary

$semi_rand md5(time()); $mime_boundary "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment

$headers .= "\nMIME-Version: 1.0\n" "Content-Type: multipart/mixed;\n" " boundary=\"{$mime_boundary}\"";

// multipart boundary 



$message "This is a multi-part message in MIME format.\n\n" "--{$mime_boundary}\n" "Content-Type: text/html; charset=\"iso-8859-1\"\n" "Content-Transfer-Encoding: 7bit\n\n" $message1 "\n\n"; $message .= "--{$mime_boundary}\n"

// preparing attachments 

for($x=0;$x<count($files);$x++){
 
$file fopen($files[$x],"rb");
 
$data fread($file,filesize($files[$x]));
 
fclose($file);
 
$data chunk_split(base64_encode($data)); 


 
$message .= "Content-Type: {\"application/octet-stream\"};\n" " name=\"$files1[$x]\"\n" .
 
"Content-Disposition: attachment;\n" " filename=\"$files1[$x]\"\n" .
 
"Content-Transfer-Encoding: base64\n\n" $data "\n\n";
 
$message .= "--{$mime_boundary}\n";
}
//echo $message ;
 
$to 'rajeevphp2011@gmail.com';
if(
mail($to $subject $message $headers )){

echo 
' Successfully Send';

} else {

echo 
' Please Try Agein ';

}
}
echo 
' invalid data'; ?>


Friday, March 16, 2012

CakePHP Framework for XAMPP and WAMP


for run cakephp freamwork on XAMPP server change


xampp/apache/conf/httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so

remove # befor it



for tutorial

http://www.sitepoint.com/application-development-cakephp/


1. download cakephp

2. app//Config/database.php // for database connection 

3.  app//Config/core.php  
  line no : 187
// copy this cod or any other number value
 Configure::write('Security.salt', '375698373538389654213024796542158345345435328930');

  line no: 192 
// copy this code or any other alphanumeric value 
 Configure::write('Security.cipherSeed', 'tyda1212dDSEASASdWayYui4deasd121212121sdsaEdrMnh'); 


4.Now go to  MOdel Folder and create " post.php " page  (page name and modal name are same )

app/Model/Post.php

<?php class Post extends AppModel {
}

5. Now go to  Controller Folder and create " PostController.php " page  (page name and Controller name are same 


app/Controller/PostController.php

 
<?php

class PostController extends AppController {
    
public $helpers = array('Html''Form''Session');
    
public $components = array('Session');

    
public function index() {
        
$this->set('posts'$this->Post->find('all'));
    }
}


6.  Now go to  view Folder and create " post/index.ctp " page  Controller function name and page name.ctp are same 


app/view/post/index.ctp  


<h1Welcome in Cake PHP home Page</h1>

noteURL Calling method 

modal_name
/function_name(in Controller file )

Thursday, March 15, 2012

cut string in JavaScript using substr function

String : HH:MM:AMPM


syntex : 


var cutstr = string.substr(startIndex , Length) ; 


CODE :- 
<script>
function cutstring(){

btime = 'HH:MM:AMPM ';

var hh = btime.substr(0,2);
var mm = btime.substr(3,2);
var ampm =btime.substr(6,2);
alert(hh);
alert(mm);
alert(ampm);

}
</script>
<b> String :  HH:MM:AMPM </b>
<input type="button" onclick="cutstring()" name="button" value="click " />

$.ajax method ,


$.ajax({
  type: 'POST', // post , get
  url: "file.php",
  data: {name: "Rajeev", time: "2pm"},
  success: function(result,status,xhr){
   alert(result); alert(status); alert(xhr);
  },
  error: function(xhr,status,error){ alert(status);
  }
 
  });

submit form using javascript


submit form using javascript   submit form using javascript  submit form using javascript

First name:
Last name:





<script type="text/javascript">
function formSubmit()
{
document.getElementById("formid").submit();
}
</script>


<form id="formid" action="myform.php">
First name: <input type="text" name="fname" /><br />
Last name: <input type="text" name="lname" /><br /><br />

<input type="button" onclick="formSubmit()" value="Submit form" />
</form>

how to copy data from one table to another table in mysql


INSERT  INTO  TABLE2  SELECT  *  FROM  TABLE1

INSERT INTO TABLE2 (COL1, COL2, COL3) SELECT COL1, COL4, COL7 FROM TABLE1

copy table one database to another database 

CREATE TABLE database2.`tablename2` SELECT * FROM database1.`tablename1`

NOTE:
 it must you have database1 , database2 and tablename1
 
Create similar table in mysql 
CREATE TABLE new_table_name LIKE tablename2;

rename table in mysql 
RENAME TABLE   table1 TO  table2  ;



Wednesday, March 14, 2012

important url

Call PHP Function In JavaScript Using Ajax

how to call php function from javascript function


1. create Folder on WWW Or htdocs (on your computer)

2. create index.php page on your folder and paste this code


index.php

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 



<script>
function addsearchproduct(x){  
// this is JavaScript  function  


$.ajax({
  type: 'POST',
  url: "function.php?f=phpFunction&p="+x, 

       // call php function , phpFunction=function Name , x= parameter 
  data: {},
  success: function(data1){
        alert(data1);
  }
});
           

}
</script>

<input type="button" value="call Php Function" onclick="addsearchproduct('pass value');"  />

 



3. create function.php  page on your folder and paste this code

 function.php 

<?php 
if(function_exists($_GET['f'])) { // get function name and parameter  $_GET['f']($_GET["p"]);
} else {
echo 
'Method Not Exist';
}


function 
phpFunction($val=''){      // create php function here  
echo $val ;
 
 }
 
 



4. run your index.php file



 

Mail Script in PHP


//error_reporting(0);
//ini_set('display_errors','off');
//ini_set('memory_limit', '-1');


 <?php
 
if(isset($_POST) && !empty ($_POST["txtname"]) ){



$name strip($_POST['txtname']); 
$mail strip($_POST['txtemail']); 
$mobile strip($_POST['txtmobile']); 

$headers =  "From: ".$mail."\r\n"

$headers .= 'MIME-Version: 1.0' "\r\n"
$headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n"
$headers .= "\r\nX-Mailer: PHP/" phpversion(); 

$subject " Mail for related to your query ";
$message "Name: " $name "<br> Mobile No: " $mobile"<br/>Email Id:".$email   ;

 
$to EMAIL_TO // define php constant 


 
if(mail($to $subject $message $headers )){ 


header('location: yourpage.php?msg=mail send successfuly '); 


} else { 



header("location: yourpage.php?msg=please try again ");

}
}
?>

Select All Check Box on clock

Imperative
Object-Oriented
Functional

Select All

Code : 


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script type="text/javascript">

$(document).ready(function()
{
$("#selectAll").click(function()
{
var checked_status = this.checked;
$("input[name=checkBoxName]").each(function()
{
this.checked = checked_status;
});
});
});

</script>

<input type="checkbox" name="checkBoxName" value="Imperative">Imperative<br>
<input type="checkbox" name="checkBoxName" value="Object-Oriented">Object-Oriented<br>
<input type="checkbox" name="checkBoxName" value="Functional">Functional<br><br>

<input type="checkbox" id="selectAll">Select All<br>

Array Terminology In PHP


<?php // Create a  array in PHP . 

$array = array(12345);
print_r($array); // prient array value HERE
echo '<br> unset array <br>' ; // Now unset all array element
foreach ($array as $i => $value) {
unset(
$array[$i]);

}
//print_r($array);

// Append an item (after $array[4] , next value store in $array[5] ).
echo '<br> echo appending array <br>' ;

$array[] = 6; print_r($array);
// Restart index

echo '<br> echo Restart index array <br>' 
$array array_values($array);
$array[] = 7;
print_r($array); ?>

Simple Function Example in PHP

<?php 
function first () {
function 
second() {
echo 
'I am  first function.';
}
echo 
'I am  second function.<br/>';
}
// here it must first you call function first()  then second()  function 

first(); // Print I am  second function 
second(); // Print I am  first function 
?>
This example use for handle to multiple Function In php

simple costume function in PHP for Add Two Values


<?php // firat method 

function add($a$b) {
echo 
$a+$b ;
}
add(5,3); 

?>


<?php // second method

function addsecond($a$b){
return 
$a+$b;
}
echo 
addsecond(6,4); 

?>


<?php  // third method 

function addthird($a,$b){ $c $a+$b ;
return 
$c ;
}
echo 
addthird(6,6);
?>

Create Constructor In PHP Example


<?php // constructor Example 


class class1 // create class 


function class1(){ 

echo 'this is a simple constructor <br>' ; } // create constructor here 

function myname(){  // create function 



echo 'my name is Rajeev Dhar Dwivedi<br>' ;
}

function 
addvalue($a$b){  //  create function 

echo $a+$b;
}

};
?>
<?php

$a 
= new class1(); // create object here

$a->myname();   // call function here 
$a->addvalue(5,10); ?>
OUTPUT :
this is a simple constructor 
my name is Rajeev Dhar Dwivedi
15

Create Class and Object In PHP simple Example


<?php class class1 // create class 


function myname(){  // create function 

echo 'my name is Rajeev Dhar Dwivedi' ;
}

function 
addvalue($a$b){  //  create another function
echo $a+$b;
}

};
?>
<?php

$a = new class1(); // create object here
$a->myname();   // call myname() function here 
echo '<br>'; $a->addvalue(5,10); // call addvalue() function here 


?>
OUTPUT :

my name is Rajeev Dhar Dwivedi
15 

null inputbox on click using javaScript



code : 



<input type="text" name="name" value="click here" onClick="(this.value='')" ;  />