tutorial101 is the one place for high quality web development, Web Design and software development tutorials and Resources programming. Learn cutting edge techniques in web development, design and software development, download source components and participate in the community.
<script type="text/javascript"> function register(){ //when the button is pressed, this function will be executed. $.ajax({ type: "POST", // AJAX function url: "submit_data.php", //Method data: "username=" + document.getElementById("username").value + "&email=" + document.getElementById("email").value, // executed when the button is pressed. success: function(html){ $("#response").html(html); //response html output echo } });
Generate RSS Feed with PHP <?php include('db.php'); $sql = "SELECT * FROM site_data ORDER BY id DESC LIMIT 20"; $query = mysql_query($sql) or die(mysql_error());
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='UTF-8'?> <rss version='2.0'> <channel> <title>r-ednalan.blogspot.com | Programming Blog </title> <link>http://r-ednalan.blogspot.com</link> <description>Programming Blog </description> <language>en-us</language>";
javascript Accept terms before submitting the form you must accept term and condition <script> var checkobj function agreesubmit(el){ checkobj=el if (document.all||document.getElementById){ for (i=0;i<checkobj.form.length;i++){ var tempobj=checkobj.form.elements[i] if(tempobj.type.toLowerCase()=="submit") tempobj.disabled=!checkobj.checked } } }
function defaultagree(el){ if (!document.all&&!document.getElementById){ if (window.checkobj&&checkobj.checked) return true else{ alert("Please read/accept terms to submit form") return false } } } document.forms.agreeform.agreecheck.checked=false </script> <form name="agreeform" onSubmit="return defaultagree(this)"> <input name="agreecheck" type="checkbox" onClick="agreesubmit(this)"><b>I agree to the above terms</b><br> <input type="Submit" value="Submit!" disabled> </form>
<script type="text/javascript"> var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i function checkmail(e){ var returnval=emailfilter.test(e.value) if (returnval==false){ alert("Please enter a valid email address.") e.select() } return returnval } </script>
1. Prevent Firefox Scrollbar Jump
Firefox usually hides the vertical scrollbar if size of the content is less than the visible window but you can fix that using this simple CSS trick. html{ overflow-y:scroll; }
2. Cross Browser Minimum Height
Internet Explorer does not understand the min-height property but here’s the CSS trick to accomplish that in IE. #container{ height:auto !important;/*all browsers except ie6 will respect the !important flag*/ min-height:500px; height:500px;/*Should have the same value as the min height above*/ }
3. Highlight links that open in a new window
a[target="_blank"]:before,
a[target="new"]:before {
margin:0 5px 0 0;
padding:1px;
outline:1px solid #333;
color:#333;
background:#ff9;
font:12px "Zapf Dingbats";
content: "\279C";
}
4. Drop Caps Using CSS
p:first-letter{
display:block;
margin:5px 0 0 5px;
float:left;
color:#FF3366;
font-size:3.0em;
font-family:Georgia;
}
5. Cross Browser Opacity
CSS3 standard includes the opacity property, but not every browser supports it, here’s the CSS trick for cross browser transparency. .transparent_class {
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}
6. Vertical centering with line-height
If you are using fixed height container and need to vertically center the text, use the line-height property to do that perfectly. line-height:30px;
4. Remove vertical textarea scrollbar in IE
IE adds a vertical scrollbar to textarea input fields regardless of the height of content in it. You can fix that with this simple CSS trick. textarea{
overflow:auto;
}
8. Highlight Text Input Fields
highlight the input field currently in focus. This trick does not work in IE though. input[type=text]:focus, input[type=password]:focus{
border:2px solid #000;
}
10. Text Shadow Property in CSS3
The text-shadow property looks cool, but it is currently not supported by major browsers including Firefox 3.0, but will be supported in Firefox 3.1 beta. Browsers that support this CSS3 property are Safari 3+, Konquerer, Opera9.5+ and iCab. text-shadow: 3px 3px 4px #999; text-shadow: 0 1px 0 #FFFFFF;
11. z-index - content slider block cover over the drop-down menu Adding z-index: 0; in the contentslider.css fixes it
#slider { z-index: 0; }
In real php you would have collected the GET Parameters from a URL like thiswww.example.com/test.php?id=1using the $_GET variable in this fashion $get_variable = $_GET['id']; You can also do the same in CakePHP. In CakePHP if you are passing parameters in the URL, then the URL would appear like this (also they are named) http://www.example.com/test/view/id:1 the controller like this
function view(id=null){ $get_variable = $this->params['named']['id']; }
or
http://www.example.com/test/view/1/submit:yes
function view($id=null, $submit=null){ $get_variable_submit = $this->params['named']['submit']; }
// define the filename extensions define('ALLOWED_FILENAMES', 'jpg|jpeg|gif|png'); // define a directory define('IMAGE_DIR', 'image');
// check against a regexp for an actual http url and for a valid filename, $url = "http://www.philwebcreative.com/philweb_logo.jpg"; if(!preg_match('#^http://.*([^/]+\.('.ALLOWED_FILENAMES.'))$#', $url, $m)) { die('Invalid url given'); }
// try getting the image if(!$img = file_get_contents($url)) { die('Getting that file failed'); }
// try writing the file with the original filename if(!$f = fopen(IMAGE_DIR.'/'.$m[1], 'w')) { die('Opening file for writing failed'); }
if (fwrite($f, $img) === FALSE) { die('Could not write to the file'); }