The user can choose values from a drop down. When the user chooses a field underneath it will display a rating box generated from the selected value from mysql, so it’s depending on what the user chooses from the drop down list.
If the user chooses chair it should insert chair into the field ‘toto’ along with the values name and address, so the field will automatically generate. How can that be done.
This is the code
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
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","des.php?q="+str+"&na=<?php echo $_GET['na']; ?>"+"&pr=<?php echo $_GET['pr']; ?>"+"&id=<?php echo $_GET['id']; ?>"+"&be=<?php echo $_GET['be']; ?>",true);
xmlhttp.send("");
}
</script>
<?php
if (isset($_POST['submit']))
{
search(); //call the search function
}else{
//end if
/*------------------------------------------------------------------------
show the search form
------------------------------------------------------------------------*/
//call the dropdown function which creates an html string to build a select box for each element
$pr = dropdown('pr','behan');
$na = dropdown('na','behan');
$om = dropdown('om','behan');
$id=$_GET["id"];
echo "
<h1><P ALIGN='center'> Rate {$_GET['be']},
{$_GET['na']} </P></h1> <p>
<br><br>
<tr>
<form>
<select name='select1' onchange='showUser(this.value)'>
<option value='book'>Book</option>
<option value='chair'>chair</option>
<option value='sun'>Sun</option>
</select>
<div id='txtHint'></div>
</form>";
}
function dropdown($field, $table)
{
//initialize variables
$oHTML = '';
$result = '';
//check to see if the field is passed correctly
if (($field == "")||($table == ""))
{
die("No column or table specified to create drop down from!");
}
$sql = "select distinct($field) from $table";
//call the db function and run the query
$result = conn($sql);
//if no results are found to create a drop down return a textbox
if ((!$result) ||(mysql_num_rows($result)==0))
{
$oHTML .= "<input type='text' name='$field' value='' size='15'>";
}elseif (($result)&&(mysql_num_rows($result)>0)){
//build the select box out of the results
while ($rows = mysql_fetch_array($result))
{
$oHTML .= "<option value='".$rows[$field]."'>".$rows[$field]."</option>\n";
}
$oHTML .= "</select>\n";
}
//send the value back to the calling code
return $oHTML;
}//end function