Ajax Request

Hi, i am giving here a complete javascript code to do a ajax request that runs on any browser.This example has a text box and a div below itwhen you type a user name in text box it will fetch matching results by like query and show you rest formating you can do as u wish.

<html>
<body>

<script type=”text/javascript”>
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject(”Msxml2.XMLHTTP”);
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject(”Microsoft.XMLHTTP”);
}
catch (e)
{
alert(”Your browser does not support AJAX!”);
return false;
}
}
}

xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
//alert(xmlHttp.responseText);
document.getElementById(”hint”).innerHTML=xmlHttp.responseText;
}
else
{
alert(”failure”);
}
}
}

//xmlHttp.open(”GET”,”ajax.php?username=”+document.
getElementById(’username’).value,true);

//for get
//xmlHttp.send(null);   //for get

xmlHttp.open(”post”,”ajax.php”,true);  //for post
var query=”username=”+document.getElementById(’username’).value;  //for post
xmlHttp.setRequestHeader(”Content-Type”, “application/x-www-form-urlencoded”);

//for post
xmlHttp.send(query);   //for post

}
</script>

<form name=”myForm”>
Name: <input type=”text” onkeyup=”ajaxFunction();” name=”username” id=”username”>
Hint: <div id=”hint”></div>
</form>
</body></html>

This is the html file and here is a php code for server side processing-

<?php
$username=$_REQUEST['username'];
if($mysqli=new mysqli(’localhost’,'root’,”,’test’))
{
//echo”conected”;
$query=”select login from user where login like ‘”.$username.”%’”;
$query_result=mysqli_query($mysqli,$query);
while($row=mysqli_fetch_array($query_result))
{
$query_array[]=$row['login'];
}

echo $query_array[0].’ ‘.$query_array[1];
}
else
{
echo “Sorry! Unable to connect”;
}
?>



Problem With form submit using javascript submit function

Hi,

i want to share one experience with all of you that why your form is not submiting using javascript’s submit function if everything is correct, one reason that i have faced is if there is any html elment(like Button ,submit button, any text box etc) whose name is submit then it will never work.

So rename your elment first then try again.

function submitform()
{
document.myform.submit();
}

Edit a web page in browser with javacsript

Guy’s i am going to tell you a interesting way to change the text content of a website in browser, to see how it looks. the way is very simple just copy the given below js code and paste it in the adress bar (where you type the url of a site to open )  . Remember before pasting this code delete all the adress written over there like www.something.com , and then paste this javascript and press enter.

Now you can change the content of a site. Enjoy!!!!

javascript:document.body.contentEditable='true';
document.designMode='on';
void 0

Remove Dotted Outlines From Buttons or links

Many of us have seen that in Firefox a dotted outline appears around buttons or links, when they becomes active . It looks more bad when we are using a background image, so we don’t like them and want to get rid of that.

here is the solutions:

For Links you can add a class like this: a {outline:none;}

For Buttons you have to add this : onFocus=”this.blur();”

They works perfectly without any side effect.

Select and unselect all checkbox using one master checkbox

<form method=”post” action=”something.php”>

<input type=”checkbox” name=”mainbox”  id=”mainbox” value=”" onclick=”checkstatus()”>

<input type=”checkbox” name=”anyname1″  id=”anyname1″ value=”1″ >
<input type=”checkbox” name=”anyname2″  id=”anyname1″ value=”2″ >
<input type=”checkbox” name=”anyname3″  id=”anyname1″ value=”3″ >
<input type=”checkbox” name=”anyname4″  id=”anyname1″ value=”4″ >
<from>
####################################################################
<script>
function checkstatus()
{
if(document.getElementById(“mainbox”).checked==true)
{
alert(“checked”);
checkbox = document.getElementsByTagName(‘input’);
for (i = 0; i < checkbox.length; i++)
{
checkbox[i].checked = true;
}

}
else
{
alert(“unchecked”);
checkbox = document.getElementsByTagName(‘input’);
for (i = 0; i < checkbox.length; i++)
{
checkbox[i].checked = false;
}

}
}
</script>