Retrieve value from database using drop down list
Posted: Mon Feb 14, 2011 1:40 am
I want to do search function using 2 drop down list, 1 to list down criteria, another one to prompt the value from database.
I can do search by using text field but still have some problem include file for drop down list.
This is code for searchform.php
if I wan change (val == "a") from text box to drop down list by including name.php, Anyone can help?
name.php
I appreciate your help. Thanks
I can do search by using text field but still have some problem include file for drop down list.
This is code for searchform.php
Code: Select all
<script language="JavaScript">
function setmode(m)
{
var w = m.selectedIndex;
var selected_text = m.options[w].text;
if (m.options[m.selectedIndex].value == '#') return;
if (m.options[m.selectedIndex].value == "a") mode = "a";
if (m.options[m.selectedIndex].value == "b") mode = "b";
}
function showSelected(val)
{
if (val == "a")
{
document.getElementById('dv').style.display = 'none';
document.getElementById('image').style.display = 'none';
var newDiv = "<input type='text' name='keyword'>";
document.getElementById('selectedResult').innerHTML = " Staff Name : " + newDiv;
}
if (val == "b")
{
}
}
function app(f)
{
url = "search.php?mode="+mode+"&key="+document.getElementById('keyword').value;
url = encodeURI(url);
f.action = url;
f.submit();
return true;
}
function validateForm()
{
var okSoFar=true;
var f=document.track;
if (f.criteria.value == "#" && okSoFar)
{
ok=false
alert("Please Select A Search Option.")
f.criteria.focus()
}
if (ok==true)
{
f.submit();
}
}
</script>
<head><title>Search </title>
</head>
<div align="center">
<form action="search.php" method="post" name="search" onsubmit="">
<table>
<tr><b>Search for Translation Task</b></tr>
<tr>
<td>Search By: </td>
<td><select name="criteria" onchange="javascript:showSelected(this.value)" id="theValue">
<option value="#">[Select Search Option]</option>
<option value="a">Staff Name</option>
<option value="b">Guest</option>
</select></td>
</tr>
<tr>
<td></td>
<td align="right"><input type="button" value="SEARCH" onclick="validateForm();"></td>
</tr>
</table>
</form>
?>
name.php
Code: Select all
<?php
include "../opendb.php";
$sql="select name from staff";
$res=mysql_query($sql);
$num=mysql_num_rows($res);
echo "<select name=\"staff\">";
echo "<option value=''>--- Please Select an staff ---</option>";
for($i=0; $i<$num; $i++)
{
$row=mysql_fetch_array($res);
echo "<option value='".ucwords($row['staff'])."'>".ucwords($row['staff'])."</option>";
}
echo "</select>";
include "../closedb.php";
?>