ASCII Code application(write in ASCII code)

hey guys,

open this file in browser and write anything in ASCII code, this is really nice application, which is used for any purpose.

i developed this application for my project purpose. and the best thing about this application is backspace also working as usual to delete last character.

so lets go for coding..

note : here i include online jquery file.. so to run this application internet must be there, or you can download js file and give link here.


<!DOCTYPE html>
<html>
<head>
<script src=”http://code.jquery.com/jquery-latest.js”></script&gt;
</head>
<body>
<p id=”t1″></p>
<script>
var keycode=0;
var k;
var temp;
var len;
var totallen,sublen;
var str=””;
document.onkeyup = function(e){
keycode = window.event.keyCode;
if(keycode == 8)
{
var data = document.getElementById(“t1″).innerHTML;
totallen = data.length;
sublen = totallen-len;
str=””;
for(var i = 0;i<sublen;i++)
{
str += data.charAt(i);
}
data = str;
$(“p”).empty();
$(“p”).append(str);

}
else
{
k = keycode;
temp = k.toString();

len = temp.length;
$(“p”).append(keycode);
}
}
</script>
</body>
</html>


hope you like this application!!

Redirect Page after 10 seconds

hey guys,

if you have a page you want to show for a few seconds and after that you want new page on same browser window. for example let say you want to display advertisement on your page for few second, after that you want to display website content on same browser window.

so here is code,

<?php
$book = $_GET[‘book’];
header (“Refresh: 10; url=../pdf/$book“);
?>
<html>
<head>
<title>Advertisement</title>
</head>
<body>
<h1>
<p>
Advertisement Here!!!!
</p></h1>
</body>
</html>

Note : That Bold font indicate url which you want to redirect after 10 seconds.

Find Location using IP Address

Hello guys,

This is very interesting post, to find location i used API of hostip.info website. first i need to find IP address of client. based on ip address i gonna fetch location.

For IP address of client please view find the ip address post.

here, i m using  PHP Simple HTML DOM Parser to read content from webpage.

Simple HTML DOM Parser
A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way!
Require PHP 5+.
Supports invalid HTML.
Find tags on an HTML page with selectors just like jQuery.
Extract contents from HTML in a single line.

to download Parser go to http://simplehtmldom.sourceforge.net/ site.
and include that file on top of php file.

$html = file_get_html('http://api.hostip.info/?ip='.$ip);
foreach($html->find('gml:name') as $element)
$result = @split("",$element);
$fresult = @split("",$result[1]);

This code return the exact city name.!!

hope you like it.!

Fill select box dynamically using jquery

hello ,

you may noticed in so many website while filling registration form that depend on which state you select , the next select box (city) automatically filled with city name.

This thing achieved by jquery.  let’s create it.

HTML CODE

<select id="state" name="state" onchange="getCity(this.value)">
<option>Gujarat</option>
<option>Karnataka</option>
</select>
City
<select  id="city" name="city" >
<option>Select</option>
</select>

oky now write this jquery function


function getCity(s)
{
var url="getCity.php?s="+s;
$.ajax({
url: url,
method: "post",
success: function(response){
document.getElementById("city").innerHTML = response;

}

});
}

now, create getCity.php file and write bellow code inside that. (first create voluntaryregistration table inside phpmyadmin and write connection code on top of this file)


include "inc/connect.php";
$s = $_GET['s'];
$qry = "select city from voluntaryregistration where state = '$s'";
$res = mysql_query($qry) or die(mysql_error());
while($data = mysql_fetch_row($res))
{
echo "<option value=".$data[0].">" .$data[0]. "</option>"; 

}

NOTE:

  • write jquery function inside <head> <script > … </script> </head> tag.
  • download jquery from http://code.jquery.com/jquery-1.8.3.min.js
  • add jquery file by <script src=”jquery-1.8.3.min.js > </script> on top of jquery function.

Problem:

if you have city name like “surendra nagar” then only surendra will stored in side option value ,
like <option value=”surendra” nagar> surendra nagar </option>

so if you are fetching this record by _POST or _GET variable you will get only surendra.

Solution

use this code inside php script.

while($data = mysql_fetch_row($res))
{
?>
<option value = “<?php echo $data[0]; ?>” ><?php echo $data[0]; ?></option>
<?php
}
?>

oky done!!

hope you like it!!

sending data with +sign in url

 

hello guys,

today , i got one problem

i had to send one variable through url to next page and i was fetching that variable using _GET[‘variablename’] but i couldn’t got proper value. because variable contains + sign say(b+).

code with problem

var url="searchCity.php?c="+bg;

Solution

if any variable contains + sing or other sign then use encodeURIComponent() function to encode url.

correct code

var url="searchbg.php?c="+ encodeURIComponent(bg);

Now you get full value of variable with +sign.!

Fetching images from database

hii everyone!

Fetching the images from database is quite different from fetching other data from the database.
so here is code for fetching the images from table.

view.php 

<?php
mysql_connect(“localhost”,”root”,””);
mysql_select_db(“test”);
$qry = “select id from image”;
$res = mysql_query($qry) or die(mysql_error());
while($row = mysql_fetch_array($res))
{
if(!empty($row[0]))
{
echo “<img src=image.php?id=’$row[0]‘ >”;
}
}
?>

image.php

<?php
mysql_connect(“localhost”,”root”,””);
mysql_select_db(“test”);
header(“Content-type:image/jpeg”);
$query = mysql_query(“SELECT img FROM image WHERE id = “.$_GET[‘id’]);
$row = mysql_fetch_array($query);
echo $row[‘img’];
?>

DB Structure of image table

db

Creating HTML elements dynamically using jquery

sometime during your project you need to create some html elements dynamically based on user’s choice.

for example you are providing upload facilities to user such that initially only one upload widget is available but if user want to upload more things, they will click on add button and based on that upload widgets should created and appear there.

so you need to use two methods of jquery.

  • live method
  • clone method

1) live method:

The live() method attaches one or more event handlers for selected elements, and specifies a function to run when the events occur.

Event handlers attached using the live() method will work for both current and FUTURE elements matching the selector (like a new element created by a script).

2) clone method:

The clone() method makes a copy of selected elements, including child nodes, text and attributes.

now let’s write code for creating dynamic elements.

 

<!DOCTYPE html>
<html>
<head>
<script src=”jquery.js”></script>
<script>
$(function()
{
$(‘.Add’).live(‘click’,function(e)
{
$(‘.Option:last’).after($(‘.Option:first’).clone());
});
});

</script>
</head>
<body>
<div class=’Option’><input type=’text’ name=’t1′/>
<span class=’Add’><img src=”add.png” height=”30″ width=”30″/></span>
</body>
</html>

dynamically_element

if you press add button you will get another same row of textbox and add button.!

hope you like it.!