PDA

View Full Version : How to do connection with drop down and text field


jayavani
Mar 19, 2011, 11:16 AM
hai... someone *** help me...
Food_ID:
Food_id :
Food_Name :
above is my interface... for the 1st food_ID I'm using drop down button... so now I want when I click drop down button it should fetch food_id from DB... ten when I select one ID... I wan the information about that ID show in 2nd food_id text field and the food name should appear in food_name text field... *** help...

below I attach my code...
**************************************…
<?php
include 'include/opendb.php';
require_once("models/config.php");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-…
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>add new</title>
</head>

<body>

<div align="center">WELCOME TO AMIGO WIRELESS RESTAURANT SYSTEM</div>
<p align="center"> FOOD</p>
<p align="center"><label>
<div align="left">
<p><strong>Food_ID: </strong>
<select name="menu" id="menu">
<?php

$result = mysql_query('SELECT food_id , food_name FROM food') or exit(mysql_error());

while ($row = mysql_fetch_assoc($result))
{


echo '<option value="' . $row['food_id'] . '">' . $row['food_id'] . '</option>';


}
echo '</select>';

?>
</select>
<p>Food_id :
<input type="text" name="id"id"id" />

<p>
<p>Food_Name :
<input type="id" name="name"text"name"name""name"form1" />
<p>F

<form id="form1" name="post" method="" action="center">
<div align="submit">
<input type="update" name="update" id="new" value="submit" />
<input type="edit" name="edit" id="edit" value="reset" />
<input type="clear" name="clear" id="clear" value="submit" />
<input type="delete" name="delete" id="delete" value="center"> </p>
</body>
</html>
**************************************…
with above code I'm able to see food_ID in drop down button but I don't know how to pass that to text field...

thanking in advance...

rlerne
Oct 22, 2011, 10:31 PM
I'm finding it sort of hard to read your question, so hopefully I have this right.

I'm thinking you want your drop down to show the food name, not the food ID number, correct?

Easy solution. Here's the line you have:


Echo '<option value="' . $row['food_id'] . '">' . $row['food_id'] . '</option>';


Change it to this:


Echo '<option value="' . $row['food_id'] . '">' . $row['food_name'] . '</option>';