0

Hi There!

I have a Ajax Function copied from W3Shools

I have modified them as my Requirement but it won able to send the xmlHTTP request to my PHP page for result

here the function

function showUser(str,txtId,mth,url)
{

if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {

    document.getElementById(txtId).innerHTML=xmlhttp.responseText;
  }
url = url+"?str=";
xmlhttp.open(mth,url+str,true);
xmlhttp.send();
}

The HTML Page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Ajax</title>
<script type="text/javascript" src="ajax.js"></script>
</head>
<body>
<form method="GET" action="" name="myForm" id="myForm" onkeyup="showUser('this.value','txtHint','GET','d.php');">
<input type="text" name="txtStr" id="txtStr">
<span id="txtHint" name="txtHint"></span>
</form>
</body>
</html>

and the PHP page

<?php
	$str = $_GET['str'];
	echo $str;
	echo "Hello";

?>

Is there anyone can help me please !
Thanks in Advanced

Edited by akvlko: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by mahavir123
0

onkeyup="showUser('this.value','txtHint','GET','d.php')

Instead of writing 'this.value' try below
Pass thetext field value not the form value

<form method="GET" action="" name="myForm" id="myForm" onkeyup="showUser(txtStr.value,'txtHint','GET','d.php');">

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.