TBL - Nama - Program: HTML Head Script Type Getxmlhttpobject XMLHTTP Null

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Jadi kasusnya gini,

Ada 1 buah combobox dan 1 buah textbox


Combobox digunakan untuk memilih program
dan textbox digunakan untuk menampilkan biaya dari program yang dipilih pada combobox.

struktur databasenya seperti ini :


tbl_nama_program
- id_nama_program,
- nama_nama_program
- biaya_nama_program
- status_nama_program

<html>
<head>
<script type="text/javascript">
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

function kirim(id)
{
var xmlHttp=GetXmlHttpObject()
var url="proses.php";
url1=url+"?id="+id;
xmlHttp.onreadystatechange=result;
function result()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("biaya").innerHTML=xmlHttp.responseText;
}
else
{
alert("Problem retrieving data:" + xmlhttp.statusText);
}
}
xmlHttp.open("GET",url1,true);
xmlHttp.send(null);
}
</script>
</head>
<body>

<select OnChange="kirim(this.value)">
<?php
echo "<OPTION>Pilih Porgram";
$conn = mysql_connect("localhost:3306","root","");
$sukses = mysql_select_db("namadatabasenya", $conn);
$sql = "SELECT * FROM tbl_nama_program WHERE status_nama_program='1'";
$query = mysql_query($sql,$conn);
while($data = mysql_fetch_array($query))
{
echo "<OPTION VALUE=$data[id_nama_program]>$data[nama_nama_program]</OPTION>";
}
?>
</select>

<div id="biaya">
</div>
</body>
</html>

file proses.php
PHP Code:
<?php
$conn = mysql_connect("localhost:3306","root","");
$sukses = mysql_select_db("namadatabasenya", $conn);
$id_program =$_GET['id'];
$sql = "SELECT biaya_nama_program FROM tbl_nama_program WHERE id_nama_program = '$id_program' AND sta
tus_nama_program='1'";
$query = mysql_query($sql,$conn);
$data = mysql_fetch_array($query);
echo "<input type=text value=$data[biaya_nama_program]>";
?>

You might also like