Tag Archives: html

Create a printer-friendly page

Easiest way to create a printer friendly page is by creating another css file. What I did is just removing the heading style.

CSS (save the CSS file as style-print.css)
#header is id for your header (div or table)

1
2
3
#header {
   display: none;
}

In HTML add this line

1
<link rel="stylesheet" href="style-print.css" type="text/css" media="print" />

HTML frame to cloak URL

This is HTML frame code to cloak URL. Be careful when use it on affiliate program. Some program (like clickbank) don’t allow URL cloak with this method.

1
2
3
4
5
6
7
8
<html><head>
<title>example title</title>
</head>
<frameset border=0 rows="100%,*" frameborder="no">
<frame src="http://www.example.com" frameborder="no" border=0 noresize>
<frame topmargin="0" marginwidth="0" scrolling="no" marginheight="0" frameborder="no" border="0" noresize>
</frameset>
</html>

Replace line break with

This code is used to replace line break saved in database to
in html display

$astring = str_replace(chr(13) . chr(10), "", $astring);

Updated: Actually there is a built in function for this as follow

echo nl2br($astring);

How to handle checkbox in PHP

Check box handling is bit different compared to other form objects because it can receive multiple values. Here is the HTML code for the form

1
2
<input name="fruit[]" type="checkbox" value="a" />Apple
<input name="fruit[]" type="checkbox" value="o" />Orange

and PHP code to handle the checkbox values.

1
2
3
4
5
6
7
8
9
 $fruit = $_POST['fruit'];
 if(!empty($fruit))
 {
   foreach($fruit as $value)
   {
     $string = $value.','.$string;
   }
   $value = rtrim($value, ',');
 }

Javascript code to prompt delete

This simple javascript code can be used to prompt user whether they want to proceed with an action or not. Usually be used when user click on delete or remove button/link.

The javascript code

1
2
3
4
5
6
7
8
9
10
11
12
<script LANGUAGE="JavaScript">
<!--
function confirmSubmit()
{
var agree=confirm("Are you sure you want to DELETE this record?");
if (agree)
	return true ;
else
	return false ;
}
// -->
</script>

The HTML code

1
<a href="?act=delete&id=1234" onClick="return confirmSubmit()">Delete</a>

Javascript to show/hide many divs

Javascript code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<script language="javascript">
<!--
 
var state = 'none';
 
function showhide(layer_ref) {
 
if (state == 'block') {
state = 'none';
}
else {
state = 'block';
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.display = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].display = state;
}
if (document.getElementById &&!document.all) {
hza = document.getElementById(layer_ref);
hza.style.display = state;
}
}
//--<
</script>;

HTML code

1
2
<p><a href="#" onclick="showhide('div1');">show/hide me</a></p>
<div id="div1" style="display: none;">This is the content</div>