May
AJAX problem
I have got form for string counting: (http://www.2001.genezis.eu/php_ajax_pokusy/index.html). I need, that result from php script, will be put into yellow DIV element (id="mistoZobrazeni"). Must be with AJAX and without page refresh. Sources:
pocitaj.php
<?
$text = $_GET["text"];
$vyber = $_GET["vyber"];
echo substr_count($text,$vyber);
?>
index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
<link href="styles.css" rel="stylesheet" type="text/css" />
<title>
test
</title>
<html>
<body>
<script type="text/javascript">
function vyberClanek()
{
var url = document.getElementById("vyber").value;
if (url != 0)
{
if (window.ActiveXObject)
{
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
httpRequest = new XMLHttpRequest();
}
httpRequest.open("GET", url, true);
httpRequest.onreadystatechange= function () {processRequest(); } ;
httpRequest.send(null);
}
else
{
document.getElementById("mistoZobrazeni").innerHTM L = "";
}
}
function processRequest()
{
if (httpRequest.readyState == 4)
{
if(httpRequest.status == 200)
{
var mistoZobrazeni = document.getElementById("mistoZobrazeni");
mistoZobrazeni.innerHTML = httpRequest.responseText;
}
else
{
alert("Chyba pri nacitani stanky"+ httpRequest.status +":"+ httpRequest.statusText);
}
}
}
</script>
<form name=f value="pocitaj.php" action="pocitaj.php" method="GET">
<textarea value="text" name=text rows="8" cols="40"></textarea>
<br> Pocet znakov
<select name="vyber" id="vyber">
<option value="a"> a
</option>
<option value="b"> b
</option>
</select>
<input type="submit">
</form>
<div id="mistoZobrazeni">
</div>
</body>
</html>
Can you help me? And sorry for my poor english.
Relevant Links

