Monday, 26 March 2012

How to launch jQuery Fancybox on page load?

//first include fancybox javascript file and jquery javascript file.

<script type="text/javascript">

jQuery(document).ready(function() {
$("a#various2").trigger('click');
});
</script>

Friday, 23 March 2012

how to remove any character using javascript?

I am removing only " - (dash), . (dot), (space) in this exmple.

function dotrm(cit)
{
var cl=cit.length;
var ch=cit;
for(l=0;l<=cl;l++)
{
if(cit[l] == '.' || cit[l] == ' ' || cit[l]=='-')
{
ch=cit.replace(cit[l],'');
}
}
document.getElementById("city").value=ch;
}

Saturday, 17 March 2012

how to backup mysql database using php?

<?php
$backfile="a.sql";
$command="mysqldump  -u root test>$backfile";//
system($command);
?>

Friday, 16 March 2012

how to validate password allow space in middle of string

function spc(str)
{
var l=str.length;//check length of string
for(var i=0;i<l;i++)
{
if(str[0]==' ' || str[str.length-1]==' ')//check first & last character of password
{
document.getElementById("spa_error").innerHTML='Space key cannot be used for the first or last character of your password';
}else
{
document.getElementById("spa_error").innerHTML='';
}
}
}

Monday, 12 March 2012

how to use trim() function in IE below version

Use this function in head section of your webpage and then use trim() function.

if(typeof String.prototype.trim !== 'function') {
  String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, '');
  }
}

Saturday, 10 March 2012

How to add top and bottam pagination in datatable?

First open  jquery.datatables.js file and find   this.sDom = 'lfrtip'; or this.sDom  and then write below code inplace of previous code.

this.sDom = '<"top"iflp>t<iflp>';

 

How to validate multiple checkbox?

var adfa=0;
var chk=document.getElementById("tbl");//table id
for(var i=0;i < chk.rows.length;i++)
{
var inputs = chk.rows[i].getElementsByTagName('input');
if(inputs[0].checked==true)
{
adfa=1;
}
}
if(adfa==1)
{
//alert("true");
if(val=='delete'){
var ans=confirm('Are you sure want to delete?');
if(ans)
document.forms[id].submit();
}
}else
{
alert("No entry was selected to be deleted");
}

Saturday, 3 March 2012

PHP mail with attachment

<?php

//Set Email Subject
$subject = $_POST['sub'];
$message_email=$_POST['message'];
$message_email.='<br><br><br>'.$data;

//define the from \ reply to headers
$headers = "From: darshakkumarshah@mkics.in\r\nReply-To: darshakkumarshah@mkics.in";

//create a unique boundary string to delimit different parts of the email (plain text, html, file attachment)
$random_hash = md5(date('r', time()));

//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks for sending
$attachment = chunk_split(base64_encode(file_get_contents($file_nm)));

//define the body of the message.
$message = "--PHP-mixed-$random_hash\r\n"
."Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
$message .= "--PHP-alt-$random_hash\r\n"
."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n";

//Insert the plain text message.
$message .= strip_tags($data);
$message .= "\r\n\r\n--PHP-alt-$random_hash\r\n"
."Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n";

//Insert the html message.
$message .= $message_email;
$message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";

//include attachment
if(isset($_POST['checkbox']))
{
$message .= "--PHP-mixed-$random_hash\r\n"
."Content-Type: application/pdf; name=".$file_nm."\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-Disposition: attachment\r\n\r\n";
$message .= $attachment;
$message .= "/r/n--PHP-mixed-$random_hash--";
}

//send the email
$mail = mail( $to, $subject , $message, $headers );

?>