Replace line break with
March 1st, 2010
No comments
This code is used to replace line break saved in database to
in html display
$astring = str_replace(chr(13) . chr(10), "", $astring);
This code is used to replace line break saved in database to
in html display
$astring = str_replace(chr(13) . chr(10), "", $astring);
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 type="checkbox" name="fruit[]" value="a" />Apple<br /> <input type="checkbox" name="fruit[]" value="o" />Orange<br /> |
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) { echo($value); echo("<br />"); } } |
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 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> |