a few
weeks ago, I try to figured out how to
choose variable option besides select object(<select>) , it will be nice if I make new popup form for
choosing option and send variable value from it to parent form (Read Send Variable Value From Popup to Parent) ,Off
course., the variable that I choose is from some table in mySql. Just look this
picture below
the picture above, we use select object.
Now I make other way to find department data.
I need 2 file two make new search data from popup form
first think make a file choosepop.php
<html>
<head>
<title>Untitled Document</title>
<script language="javascript">
//var b;
function getValueDept(myid, mydept)
{
document.getElementById('myid').value = myid;
document.getElementById('mydept').value = mydept;
}
function findDept(){
//var dinas = document.myform.dinas.value;
window.open('search.php','cbar','width=400','height=400','toolbar=no','status=no');
}
</script>
</head>
<body>
<form name="myrelease" action="<?php $PHP_SELF ?>" method="post">
<table>
<tr><td>Departement : </td><td>:</td><td><input type="text" name="dept" id="mydept"><input type="hidden" name="myid" id="myid">
<input type="button" value="find" onClick="findDept()"></td></tr>
</table>
</form>
</body>
</html>
Save script above to choosepop.php
and then make a new file php with script below
<html>
<head>
<title>Untitled Document</title>
<script language="javascript">
function SendValueToParent()
{
var mydept = document.getElementById('mydept').value;
var myid = document.getElementById('myid').value;
window.opener.getValueDept(myid, mydept);
window.close();
// return false;
}
function pilihan()
{
var a = document.mysearch.jml_rec.value;
if(a>1){
for (var i= 0; i < a ; i++) {
if(document.mysearch.iddept[i].checked){
var myid = document.mysearch.iddept[i].value;
document.mysearch.myid.value = myid;
// return myid;
document.mysearch.mydept.value =
document.mysearch.dept[i].value;
}
}
}else{
var a = document.mysearch.iddept.value;
document.mysearch.myid.value = a;
//return a;
var b = document.mysearch.dept.value
document.mysearch.mydept.value = b;
}
}
</script>
</head>
<body>
<?php
//==connection ==
$server = "localhost";
$user = "root";
$password = "";
$conn = mysql_connect ($server, $user, $password) or die ("koneksi gagal");
$db = "company";
//==========
$querydept = "select * from departement";
$resultdept = mysql_db_query($db, $querydept, $conn) or die ('Salah Query');
$jml_rec = mysql_num_rows($resultdept);
?>
<table>
<form name="mysearch">
<tr>
<td>No</td>
<td>Departement</td></tr>
<?php
$a = 1;
while(list($id, $dept) = mysql_fetch_row($resultdept)){
?>
<tr><td><?php echo $a ?></td><td><input type="radio" value="<?php echo $id ?>" name="iddept" onClick="pilihan()">
<input type="hidden" name="dept" value="<?php echo $dept ?>"><?php echo $dept ?></td>
</tr>
<?php
$a++;
}
mysql_free_result($resultdept);
?>
<tr><td colspan="3"><input type="button" value="choose" onClick="SendValueToParent()">
<input type="hidden" name="mydept" id="mydept">
<input type="hidden" name="myid" id="myid"><input type="hidden" name="jml_rec" value="<?php echo $jml_rec ?>"></td></tr>
</form>
</table></body>
</html>
Save the script to search.php
do not forget to create a table to your mysql databases :
we need to create table departement
create table departemet(id int(3) auto_increment not null, department varchar(50) not null, primary key(id));
the result will be like picture below
Ok.. that All for today...
please give your comments,
you can download source
here
Judul : Make a simple search popup form with php.
Deskripsi : a few weeks ago, I try to figured out how to choose variable option besides select object(<select>) , it will be nice if I ma...