You are on page 1of 4

Herii Purnama

125410101
TI 02
-------------------------------------Tugas 3 -----------------------------Skrip
1.Ajak
<html>
<head>
<style type="text/css">
#kotak{
width: 50pc;
height: 100000pc;
}
</style>
<script>
function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "gethint.php?q=" + str, true);
xmlhttp.send();
}
}
function ambil(nim)
{
if (nim.length == 0) {
document.getElementById("txtNama").innerHTML = "";
document.getElementById("txtAlamat").innerHTML = "";
return;
} else
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtNama").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "getNama.php?tnim=" + nim, true);
xmlhttp.send();
var xmlhttp3 = new XMLHttpRequest();
xmlhttp3.onreadystatechange = function() {
if (xmlhttp3.readyState == 4 && xmlhttp3.status == 200) {
document.getElementById("txtAlamat").innerHTML = xmlhttp3.responseText;
}
}
xmlhttp3.open("GET", "getAlamat.php?tnim=" + nim, true);
xmlhttp3.send();

Herii Purnama
125410101
TI 02
}

</script>
</head>
<body>
<p><b>----------------- Masukkan NIM ------------------</b></p>
<div id="kotak">
<form>
<table border="0px">
<tr>
<td>NIM</td>
<td>:</td>
<td>
<input type="text" name="nim" onkeyup="showHint(this.value)">
<input type="button" value="OK" onClick="ambil(nim.value)"/>
</td>
</tr>
<tr>
<td>Suggestions</td>
<td>:</td>
<td><span id="txtHint" font-size="5"></span></td>
</tr>
<tr>
<td>Nama</td>
<td>:</td>
<td><span id="txtNama"> </span></td>
</tr>
<tr>
<td>Alamat</td>
<td>:</td>
<td><span id="txtAlamat"> </span></td>
</tr>
</table>
</form>
<p>-------------------------------------------------------------------------------</p>
</div>
</body>
</html>

2.array A
<?php
$a= array(array("125410101","Heri Purnama","Prambanan"),
array("1254100110","Arif","Prambanan"),
array("125410012","Roberto","Sleman"),
array("125410019","John","Kota Tua"),
array("125410019","Joy","kali Code")
);
// get the q parameter from URL
$q = $_REQUEST["q"];
$hint = "";
if ($q !=="")
{
$q = strtolower($q);
$len=strlen($q);
for($i=0;$i<=4;$i++)

Herii Purnama
125410101
TI 02
{
if (stristr($q, substr($a[$i][0], 0, $len))) {
if ($hint === "") {
$hint = $a[$i][0];
} else {
$hint .= ", ".$a[$i][0];
}
}
}
}
// Output "no suggestion" if no hint was found or output correct values
echo $hint === "" ? "no suggestion" : $hint;
?>

3.array B
<?php
$a= array(array("125410101","Heri Purnama","Prambanan"),
array("1254100110","Arif","Prambanan"),
array("125410012","Roberto","Sleman"),
array("125410019","John","Kota Tua"),
array("125410019","Joy","kali Code")
);
$tnim = $_REQUEST["tnim"];
$hint = "";
$nim="";
$nama="";
if ($tnim !=="")
{
for($i=0;$i<=4;$i++)
{
for($j=0;$j<=2;$j++)
{
if($a[$i][0] == $tnim)
{
$nama = $a[$i][1];
}
}
}
}
echo $nama;
?>

4.array c
<?php
$a= array(array("125410101","Heri Purnama","Prambanan"),
array("1254100110","Arif","Prambanan"),
array("125410012","Roberto","Sleman"),
array("125410019","John","Kota Tua"),
array("125410019","Joy","kali Code")
);

Herii Purnama
125410101
TI 02
$tnim = $_REQUEST["tnim"];
$alamat="";
if ($tnim !=="")
{
for($i=0;$i<=4;$i++)
{
for($j=0;$j<=2;$j++)
{
if($a[$i][0] == $tnim)
{
$alamat = $a[$i][2];
}
}
}
}
echo $alamat;
?>
--- output ---