$('table').css({
'border-collapse':'collapse'
});
$('tr th').css({'background':'#666666', 'color':'#ffffff', 'font-family':'verdana', 'font-weight':'normal'});
// Here using jquery selectors
$('tr:even').css({'background':'#c3c3c3'});
$('tr:odd').css({'background':'#e3e3e3'});
Student Plus - A great resource to be intermediate to expert in different fields like jquery, css, html, php, joomla, javascript, css3, html5, mysql etc.
Search
Wednesday, September 28, 2011
Beautify table with jquery selectors :even and :odd
Friday, September 2, 2011
Get URL, URL part, URL parameters using javascript
var proto = window.location.protocol; alert( proto );this code return "http:" protocol.
If you want to get host name from the URL using javascript then you can simple write this code:
var hostName = window.location.host; alert( hostName );this code return the host name like if you are running this code in local host then it returns "localhost"
if you want to get path of the URL with javascript then use this:
var pathName = window.location.pathname; alert( pathName );this code returns the path name of the current running script like you are running the script in test.html the it return the full path name with filename test.html
Or if you want to get parameter used in URL with javascript then simply do this:
var params = window.location.search; alert( params );it returns the parameter used in the URL
now lets join all the code :
var proto = window.location.protocol; var hostName = window.location.host; var pathName = window.location.pathname; var params = window.location.search; alert( proto + hostName + pathName + params );
Tuesday, May 31, 2011
dynamic select box with jquery, php, mysql
hello friends last Saturday i was working on a Real State project and i need to build a dynamic form to submit the properties in particular state and cities. I made that dynamic form with the help of php and jquery. Here is i describe the codes one by one.
First of all we need to create a Database. And after that Create Some tables related to your project. I Create a Database name 'test' in phpmyadmin. My these codes are related to this dynamic form you can change the Database name and fields as per your requirements. After create the database create a table, in this example i create a table name 'tbl_class' with these codes :
CREATE TABLE `test`.`tbl_class` ( `id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` VARCHAR( 200 ) NOT NULL , PRIMARY KEY ( `id` ) ) ENGINE = MYISAM ;
then insert some data with the help of these commands :
INSERT INTO `test`.`tbl_class` ( `id` , `name` ) VALUES ( NULL , '10th Class' ), ( NULL , '11th Class' ), ( NULL , '12th Class' );
with the help of same steps create one more table named 'tbl_student' and also use same insert command to insert the data in 'tbl_student' table.
now it is the time to connect the database with the help of php.
here is an example to connect the database named 'connection.php' .
#make Connection
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "test";
//Connection layer
$conn = mysql_connect($hostname, $username, $password);
//Check connection and select DATABASE
if( $conn )
mysql_select_db($dbname, $conn);
else
die("Error in Connection!");
now create one more file 'index.php' and create some html stuff.
for example :
Dynamic Form
include the 'connection.php' file on the top of the 'index.php', like:
include 'connection.php';
then insert the data in the select option
#insert class data from database
$query = "select * from tbl_class";
$result = mysql_query($query) or die("Error in Query!
".mysql_error());
while($row = mysql_fetch_array( $result ))
{
echo "";
}
now it is the time to use jquery for the ajax request. Create a function with jquery to make simple the ajax request.
here is the code for the ajax request function:
create a 'getStrength.php' file to get the data through ajax request.
if(isset($_REQUEST['class']))
{
$classID = (int)$_REQUEST['class'];
$query = "select * from tbl_student where classID = '$classID'";
$result = mysql_query( $query ) or die("Error in Strength Query!");
if($classID == 0)
echo '';
else{
while($row = mysql_fetch_array($result)){
echo "";
}
}
}
the above code is for the file 'getStrength.php'. The ajax request send the data to this file and get the result through this file.
You can beautify this dynamic form with some css effects.
hopefully you will enjoy this post.
Wednesday, March 16, 2011
email validation using php
Form validation is must to prevent spam and form attacks. Email validation is also must to making a form. We use Regular Expressions for validation in PHP, which is secure and highly usable on web. preg_match() and ereg() functions are using for validation. But sometimes ereg() function produce some Deprecated Error. To prevent Deprecated Error we use preg_match for email validation. Here are some codes for Email Validation :
function email_Validate($str)
{
if(preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $str))
{
return true;
}
}
and now we use this email validation function in our form
if(!email_Validate($email))
{
echo "Email not valid!";
}
Beside PHP you can validate your email with javascript/jquery. Its quite easy to implement and use with the help of javascript/jquery. Here is my code for jquery and you can also implement these with javascript :
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
//userMail is a input box name
var email = $('#userMail').val();
if(reg.test(email) == false)
{
alert('Email Not Valid');
}
this validation help you to prevent spamming in login system or registration form.
Friday, October 29, 2010
simple login system using php
login system is very common in php. In this post you can get an idea to make a login system in php. Before the starting the coding for login system you have to check what you want to represent to the user on login panel. You have to use some CSS to give better look for login panel.
here is php code for login system :
// first we check the name of submit button is set or not
if(isset($_POST['submit']))
{
$name = $_POST['username'];
$pass = $_POST['password'];
// check the value of input box
if($name == "")
echo 'Name field is empty!';
elseif($pass == "")
echo 'Password filed is empty!';
else
{
// temporary username and password
$uname = 'user1';
$upass = '12345';
if($name == $uname && $pass == $upass)
echo 'Welcome : ' . $uname;
else
echo 'Username or Password didn't match!';
}
}
You can change username and password as you want. It just a idea for login system. Hope it will help you to develop a login system.
