<!DOCTYPE>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Image extension validation in javascript</title>
<script type="text/javascript">
function checkExtension(filename)
{
var n= filename.lastIndexOf(".");
if(n != -1) //which means filename has .
{
var st= filename.substring(n);
if(st==".jpg" || st==".jpeg" || st==".png" || st==".gif")
{ //correct extension
return true;
}
else
{
//incorrect extension
return false;
}
}
else
{
//filname don't contains .
return false;
}
}
function check()
{
var fname=document.frm.filename.value;
if(fname=='')
{
alert('select image')
return false;
}
else if(checkExtension(fname))
return true;
else
{
alert('Invalid image file. Should be a image !!!')
return false;
}
}
</script>
</head>
<body>
<h1 align="center">Image extension validation in javascript.</h1>
<div align="center">
<form name="frm" onsubmit="return check()" method="post" action="go.html">
Select File:
<input type="file" name="filename" id="filename" />
<br/> <br/>
<input type="submit" />
</form>
</div>
</body>
</html>
Friday, December 12, 2014
How to Validate Image Extension in JavaScript ?
Thursday, November 27, 2014
simple pagination in php
Below is the code to do a simple pagination in php:
See the effect here:
First page:
Middle page:
Last page:
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$rec_limit = 5;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydatabase');
/* Get total number of records */
$sql = "SELECT count(prd_code) as count_prd FROM Product_tab";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
$row = mysql_fetch_array($retval );
$rec_count = $row['count_prd'];
if( isset($_GET{'page'} ) )
{
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}
else
{
$page = 0;
$offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
$sql = "SELECT prd_code,prd_name,prd_price from product LIMIT $offset, $rec_limit";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval))
{
echo "Product id :{$row['prd_code']} <br> ".
"Product name :{$row['prd_name']} <br> ".
"Price : {$row['prd_price']} <br> ". "--------------------------------<br>";
}
if( $page > 0 && !($left_rec < $rec_limit) )
{
$last = $page - 2;
echo "<a href=\"$_PHP_SELF?page=$last\">Previous 5 Records</a> |";
echo "<a href=\"$_PHP_SELF?page=$page\">Next 5 Records</a>";
}
else if( $page == 0 )
{
echo "<a href=\"$_PHP_SELF?page=$page\">Previous 5 Records</a>";
}
else if( $left_rec < $rec_limit )
{
$last = $page - 2;
echo "<a href=\"$_PHP_SELF?page=$last\">Previous 5 Records</a>";
}
mysql_close($conn);
?>
See the effect here:
First page:
Middle page:
Last page:
About me
That's me Avnish Alok, the guy behind this blog, a Software Engineer, Blogger, Freelancer and a true technology geek indeed. I believe in the ideology of BENJAMIN FRANKLIN great quote "He that can have patience can have what he will". I retain all such qualities to be a technology geek i:e; spend my much more time with computer, treating my pc as a family member, awake up at every morning with more passion to know about new tools & technologies, dig deeply to know more about each stuff.
Apart from my profession i love to write poems and reading novels as well. I write poems of genres like inspirational and romantic.
I hold my PG degree(MCA) in Information Technology and planning to do P.H.D in the same. As I’m a blogger, it is obvious to do blogging so, CS HOT TOPICS is the outcome. With the help of this blog I share my knowledge to my friends, my colleagues and to the entire world.
ABOUT CS HOT TOPICS:
CS HOT TOPICS is a technical blog for open source enthusiasts that always updates with latest tools & technologies. As the name suggest it covers hot topics of computer programming in various languages(java, jsp, servlet, php, mysql, oracle) to name a few with latest tools(ajax, jquery). You can get more to visit here http://cshotopics.blogspot.com/
You can follow me on Google+, Facebook and Twitter, If you’d like to dig more about me.
If you’ve any Queries about Add. and content Posting, or want to provide me your feedback so that i can improve this blog further, feel free to email me at avnishalok.se@gmail.com
Subscribe to:
Posts (Atom)




