Tag Archives: Javascript

switch statement – Javascript

function displaySize(sizes){

switch (sizes) {

case “header”:sizeDim=’728 x 90′;break;

case “footer”:sizeDim=’500 x 150′;break;

case “sidebar”:sizeDim=’7263 x 181′;break;

}

document.getElementById(‘dimension’).innerHTML=sizeDim;

}

<table>

<tr>

<td>Select Position</td> <td>

<select name=”banner_position” onchange=”javascript:displaySize(this.value);”>

<option value=”>Select the position</option>

<option value=’header’  >Header</option>

<option value=’footer’ >Footer</option>

<option value=’sidebar’  >Sidebar</option>

</select>

</td>

</tr>

<tr>

<td>Upload image</td> <td> <input type=”file” name=”image” />(Size should be <span id=”dimension”></span>) </td>

</tr>

</table>

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>

Social Bookmark Sharing option

<a href="http://www.addthis.com/bookmark.php?v=250" 
onmouseover="return addthis_open(this, '', '[URL]', '[TITLE]')" 
onmouseout="addthis_close()" onclick="return addthis_sendto()">
<img src="http://s7.addthis.com/static/btn/lg-share-en.gif" 
width="125" height="16" alt="Bookmark and Share" style="border:0"></a>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js?pub=zeegal"></script>

Latest tweets in your site

<script src=”http://widgets.twimg.com/j/2/widget.js”></script><script type=”text/javascript”>// <![CDATA[new TWTR.Widget({  version: 2,  type: ‘profile’,  rpp: 4,  interval: 6000,  width: 272,  height: 300,  theme: {    shell: {      background: ‘#24838a’,      color: ‘#ffffff’    },    tweets: {      background: ‘#f5f5f5’,      color: ‘#000000’,      links: ‘#000000’    }  },  features: {    scrollbar: true,    loop: false,    live: false,    hashtags: true,    timestamp: true,    avatars: true,    behavior: ‘all’  }}).render().setUser(‘tppramod’).start();// ]]></script>

//modify the user name “tppramod”  with the desired one .

Latest tweets in your site – PHP

<?php

$username=”tppramod”; // Your Twitter username

$limit=10;//Number of tweets

if(!is_numeric($limit)){$limit = 10;}

$xml = simplexml_load_file(‘http://search.twitter.com/search.atom?q=from%3A&#8217;.urlencode($username));?>

<table>

<?php for($i=0;$i<$limit;$i++){

if(empty($xml->entry[$i]->content)) break;

$attr = $xml->entry->link[1]->attributes();

?>

<tr> <td> <img src=”<?php echo $attr[‘href’]; ?>” /> </td> <td style=” font-size:12px;”> <?php echo  $xml->entry[$i]->content; ?> </td> </tr>

<?php } ?>

</table>