1) Write an Ajax
program to display list of games stored in an array on clicking OK button.
gmatch.php
<?php
$arr=array('1'=>'khokho','2'=>'kabbadi','3'=>'golaphek','4'=>'cricket','5'=>'football','6'=>'basketball');
$value = $_GET['q'];
if($value)
{
foreach($arr as $v)
{
echo
"<br><b>".$v."</b>";
}
}
?>
slip27.html
<html>
<head>
<script>
function showMatch(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if
(window.XMLHttpRequest)
{// code for IE7+,
Firefox, Chrome, Opera, Safari
xmlhttp=new
XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new
ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if
(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","gmatch.php?q="+str,true);
xmlhttp.send();
}
</script>
</head
<body>
<p><b>Start
typing a name in the input field below:</b></p>
<input
name="submit" type="button" value="submit"
onclick="showMatch(this.value)" />
<p>Suggestions:
<span id="txtHint"></span></p>
</body>
</html>
?>
2) Write a script to
create “cricket.xml” file with multiple elements as shown below:
<CricketTeam>
<Team country=”India”>
<player>____</player>
<runs>______</runs>
<wicket>____</wicket>
</Team>
</CricketTeam>
Write a script to add multiple elements in
“cricket.xml” file of category, country=”Australia”.
CricketTeam.xml
<?xml
version="1.0" ?>
<?xml-stylesheet
type="text/css"?>
<CricketTeam>
<Team
country="India">
<player>sachin</player>
<runs>36000</runs>
<wicket>88</wicket>
</Team>
<Team
country="Australia">
<player>watsun</player>
<runs>10000</runs>
<wicket>44</wicket>
</Team>
<Team country="Pakisthan">
<player>Afridhi</player>
<runs>6000</runs>
<wicket>65</wicket>
</Team>
</CricketTeam>
CricketTeam.php
<html>
<head>
</head>
<body>
<?php
$xml=simplexml_load_file('
CricketTeam.xml')or die("cannot die");
?>
<center></b>Cricket
details</b></center>
<table
border="1">
<th>Team</th>
<th>player</th>
<th>runs</th>
<th>wicket</th>
<?php
foreach($xml->Team
as $a)
{
echo"<tr><td>".$a['country']."</td>";
echo"<td>".$a->player."</td>";
echo"<td>".$a->runs."</td>";
echo"<td>".$a->wicket."</td></tr>";
}
?>
</table>
</body>
</html>