Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Monday, January 4, 2010

Tab Menu in Javascript

Implement customize tab menu in single floor and multi floor in any language using javascript




<style type="text/css">
  .tabHold{background-color:#bbb9b5; width:400px; height:26px; margin-left:18px; margin-top:9px; float:left;}


.tabHold_1{background-color:#bbb9b5; width:400px; height:26px; margin-left:18px; margin-top:6px; float:left;}
  
  .tabmenu{width:100px; height:21px; text-align:center; font-family:Arial; font-size:13px; padding-top:3px; color:#FFFFFF; text-decoration:none; float:left; cursor:pointer;}
  .tabmenu:hover{ background-color:#FFFFFF; width:100px; height:21px; text-align:center; padding-top:3px; font-family:Arial; font-size:13px; color:#000000; text-decoration:none; float:left;}
  .tabContent{
  color:#000000;
  width:450px;
  height:100px;
  float:left;
  display:none;
  border:#CCCCCC solid 2px;

  }
  .DefaulttabContent{
  color:#000000;
  width:450px;
  height:100px;
  float:left;
  display:block;
  border:#CCCCCC solid 2px;
  }
  </style>


<script language="javascript">
  function init(){

  document.getElementById('tabmenu1').style.background='#FFFFFF';
  document.getElementById('tabmenu1').style.color='#000000';
  document.getElementById('tab1').style.display='block';


  }
  function onClickShow(TabNo,totTab){

 
  var i=1;
  for(i=1;i<=totTab;i++){
  if(i==TabNo){
  document.getElementById('tabmenu'+TabNo).style.background='#FFFFFF';
  document.getElementById('tabmenu'+TabNo).style.color='#000000';
  document.getElementById('tab'+TabNo).style.display='block';


}else{
  document.getElementById('tabmenu'+i).style.background='#bbb9b5';
  document.getElementById('tabmenu'+i).style.color='#FFFFFF';
  document.getElementById('tab'+i).style.display='none';


}


}
  
  
  }
  window.onload(init());


  </script>
  </head>
  <body>
  <div style="width:450px; float:left; border:#000000 solid 2px;">
  <div align="left" class="tabHold">
  <span class="tabmenu" onclick="onClickShow('1','8')" id="tabmenu1">Tab1</span>
  <span class="tabmenu" onclick="onClickShow('2','8')" id="tabmenu2">Tab2</span>
  <span class="tabmenu" onclick="onClickShow('3','8')" id="tabmenu3">Tab3</span>
  <span class="tabmenu" onclick="onClickShow('4','8')" id="tabmenu4">Tab4</span>
  </div>
  <div align="left" class="tabHold_1">
  <span class="tabmenu" onclick="onClickShow('5','8')" id="tabmenu5">Tab5</span>
  <span class="tabmenu" onclick="onClickShow('6','8')" id="tabmenu6">Tab6</span>
  <span class="tabmenu" onclick="onClickShow('7','8')" id="tabmenu7">Tab7</span>
  <span class="tabmenu" onclick="onClickShow('8','8')" id="tabmenu8">Tab8</span>
  </div>


<div class="DefaulttabContent" id="tab1">Text in Default Tab</div>
  <div class="tabContent" id="tab2">Text in Tab2</div>
  <div class="tabContent" id="tab3">Text in Tab3</div>
  <div class="tabContent" id="tab4">Text in Tab4</div>
  <div class="tabContent" id="tab5">Text in Tab5</div>
  <div class="tabContent" id="tab6">Text in Tab6</div>
  <div class="tabContent" id="tab7">Text in Tab7</div>
  <div class="tabContent" id="tab8">Text in Tab8</div>


</div>


Default page load :




Click on other tab :

Friday, December 4, 2009

Add/Remove dynamic rows in HTML table

Add or remove row or item form html table dynamically.





 
<SCRIPT language="javascript">
     function addRow(tableID) {

     var table = document.getElementById(tableID);

     var rowCount = table.rows.length;
     var row = table.insertRow(rowCount);

     var cell1 = row.insertCell(0);
     cell1.innerHTML = "Select Photo : ";


     var cell2 = row.insertCell(1);
     cell2.innerHTML = rowCount + 1;

     var cell3 = row.insertCell(2);
     var element2 = document.createElement("input");
     element2.type = "file";
     cell3.appendChild(element2);

     }

     function deleteRow(tableID) {
     try {
     var table = document.getElementById(tableID);
     var rowCount = table.rows.length;

     for(var i=0; i<rowCount; i++) {
     var row = table.rows[i];
     var chkbox = row.cells[0].childNodes[0];
     if(null != chkbox && true == chkbox.checked) {
     table.deleteRow(i);
     rowCount--;
     i--;
     }

     }
     }catch(e) {
     alert(e);
     }
     }

  </SCRIPT>

 

  <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />

  <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />

  <TABLE id="dataTable" width="350px" border="1">
  <TR>
  <TD>Select File : </TD>
  <TD> 1 </TD>
  <TD> <INPUT type="file" name="file" /> </TD>
  </TR>
  </TABLE>


Monday, November 23, 2009

Text Slide show in php using javascript function

To show text/field value comes database as slide show in php.
this will happen by using javascript function embed with php code.
this example will help in fetching record and display as slide show


<style type="text/css">

#featureBlog{

color:#006699; font-size:12px; font-family:Verdana, Arial, Helvetica, sans-serif; width:345px;padding-top:5px;
}
#featureBlogDesc{
color:#000000; font-size:10px; font-family:Verdana, Arial, Helvetica, sans-serif; width:345px;padding-top:5px;
}

</style>




<?php


echo'


<SCRIPT type="text/javascript">

var quotations = new Array();';





$i=0;

$sql="select title,link,desc from table";

$rs=mysql_query($sql,$dbc)or die('Error in fetching title:-'.mysql_error());

while($row=mysql_fetch_array($rs)){



echo 'quotations['.$i.']="<a href=\".$row["link"].'\"><span id=featureBlog>'.ucfirst($row["title"]).'<br><span id=featureBlogDesc>'.ucfirst($row["desc"]).'</span></a>";';

$i++;



}



echo'

function display()

{

a=Math.floor(Math.random()*quotations.length)

document.getElementById(\'quotation\').innerHTML=quotations[a]

setTimeout("display()",5000)

}

</SCRIPT>

';



?>

<div id="quotation" style="position:absolute; width:200; height:102; left:150; top:150; border-style:solid; border-width:1px; border-color:#000000;">

<SCRIPT type="text/javascript">display()</SCRIPT>

</div>

Wednesday, November 18, 2009

Share Image (Email) to your friend using Bcc email address in php

Send Image as news letter or share image to all ur friend of the site in php though email using BCC address.

This image form and take user email id and verify that email id using java script code. u can send mail to more then one friend. u can save reciver id in your database

Image Form File

<style type="text/css">

#emailtext{
font-family:Verdana;
font-size:14px;
color:#282828;

}

.txtBox {
border:#333333 solid 1px;
}
.imgBox {
border:#FF9900 solid 1px;
}
</style>

<script language="javascript">


function checkFieldEmpty(textField,mess){

var textFieldValue=textField.value;

if(textField=="" || textFieldValue.length==0){// && textField=" "){

alert(mess)

return false;

}else{

//return true;

return "";
}

}


// Javascript Email Verification function

function chkEmail(elem, errorshow){

var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(elem.value.match(emailExp)){

return "";
}else{
alert(errorshow);

return false;
}
}

function FormSubmit(theForm){

//alert("in submit");

var reason="";



reason += checkFieldEmpty(document.getElementById('senderName'),'Enter Your Name');
reason += checkFieldEmpty(document.getElementById('senderEmail'),'Enter Your Email');
reason += checkFieldEmpty(document.getElementById('recEmail'),'Enter Email To send');
reason += chkEmail(document.getElementById('senderEmail'),'Enter Your Email correct');
//reason += chkEmail(document.getElementById('recEmail'),'Enter Send To Email correct');


if(reason!=""){
alert("Some Field Need To Fill");
}else{
theForm.submit();
}
}



</script>

<table width="700" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>
<td align="center" class="imgBox"><img src="<?php echo getPath($Id,$dbc); ?> " height="600" width="700"></td>
</tr>
<tr>
<td>
<form action="sendShareImage.php" method="post" name="shareForm">
<table width="400" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td><span id="emailtext">Your Name</span></td>
</tr>
<tr>
<td><input type="text" name="senderName" id="senderName" size="50" class="txtBox"><input type="hidden" name="id" value="<?php echo $Id;?>"></td>
</tr>
<tr>
<td><span id="emailtext">Your E-mail address</span></td>
</tr>
<tr>

<td><input type="text" name="senderEmail" id="senderEmail" size="50" class="txtBox"></td>
</tr>
<tr>
<td><span id="emailtext">Your Message:-</span></td>
</tr>
<tr>

<td><textarea name="sendermsg" id="sendermsg" cols="50" rows="5" ></textarea></td>
</tr>

<tr>
<td><span id="emailtext">Recipient E-mail address</span></td>
</tr>
<tr>

<td>
<input type="text" name="recEmail" id="recEmail" size="50" class="txtBox"><br />

(use , for multiple emailId)</td>
</tr>
<tr>

<td><strong>Bcc.</strong><br /><input type="text" name="bccsenderEmail" id="bccsenderEmail" size="50" class="txtBox"></td>
</tr>
<tr>
<tr>
<td>&nbsp;</td>
<td align="right" valign="bottom"><img src="images/send.gif" onClick="FormSubmit(shareForm)" />&nbsp;&nbsp;&nbsp;</td>
</tr>
</table>
</form>

</td>
</tr>
</table>

//End of file of image form

File of mail send start

<style type="text/css">

#send{
display:block;
background-color:#00CC66;
color:#FFFFFF;
text-align:center;
}
#fail{
display:block;
background-color:#FF3300;
color:#FFFFFF;
text-align:center;
}
#tbc{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:14px;
font-weight:bold;
color:#000060;
}
</style>

<?php

$dbc=mysql_connect('localhost','root','');
mysql_select_db(db_name,$dbc);

set_time_limit(0);

$Id=$_REQUEST['id'];

$senderName=$_REQUEST['senderName'];
$sender=$_REQUEST['senderEmail'];
$receiver=$_REQUEST['recEmail'];
$senderMsg=$_REQUEST['sendermsg'];
$bccid=$_REQUEST['bccsenderEmail'];

//**********************Function to get Image Path*******************

function getPath($imgId,$dbc){

$selPath="select path,id from wallpaper where id=$imgId";
$Result=mysql_query($selPath,$dbc) or die('Error in fetch Thum Image:-'.mysql_error());
$row=mysql_fetch_array($Result);
return($row[0]);

}

//**********************End of Image Path Function********************

$sub="Image Sharing";

$headers = "From: $sender\r\n";

$headers .= "Content-type: text/html\r\n";
$headers .= "Bcc:$bccid"; //Send any bcc address

$imgPath = getPath($Id,$dbc);

$imgPath = str_replace( ' ', '%20', $imgPath );
//echo $imgPath;

$bodyTxt;

$bodyTxt='

<html>

<body>

<p>Dear friend of '.$senderName.',</p>

<img src="http://www.servername.com/wallpaper/'.$imgPath.'" height="800" width="1000"><br>

<p>
'.$senderMsg.'
</p>


<p>Thank you!</p>

</body>

</html>';

if(mail($receiver,$sub,$bodyTxt,$headers)){



$maxId="select max(id) from shareimg";
$res=mysql_query($maxId,$dbc);
$rs=mysql_fetch_row($res);
$shreId=$rs[0];
$newId=$shreId+1;
//echo $newId;
$saveId="insert into shareimg values($newId,'$senderName','$sender','$receiver','y')";
if(mysql_query($saveId,$dbc)){
echo'<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" height="81"><img src="images/successfulHeader.png" width="100%"></td>

</tr>
<tr>
<td colspan="2" valign="top"><span id="success">&nbsp;&nbsp;Successful !</span><br>
<span id="invitetbc">&nbsp;&nbsp;&nbsp;&nbsp;Your Wallpaper has been Sent</span></td>

</tr>
<tr>
<td width="158" height="185" align="left">&nbsp;&nbsp;&nbsp;&nbsp;<img src="'.getPath($Id,$dbc).'" width="140" /></td>
<td width="342" align="left" valign="middle"><span id="senderName">'.$senderName.'</span><br />
<span id="invitetbc">Your Desktop Wallpaper has been Sent to</span><br /><span id="tbc">'. $receiver.'</span></td>
</tr>
<tr>
<td colspan="2"><i><span id="invitetbc">&nbsp;&nbsp;&nbsp;&nbsp;We Invite you to:</span></i></td>

</tr>
<tr>
<td valign="middle" align="center">&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/sideimage.jpg" /></td>
<td>
<span id="tbc">

</span>


</td>
</tr>
</table>';

}

}else{
echo '<span id="send">Sending Fail</div>';
}

?>