hi, i have a script here which display an item name from database into textfield based on the combo box selection, i cn display the item name but my problem is i dont know how to display the item information into the textbox? i'm required to use php, hope my simple explanation works n_n

ex. item color
apple red
mango yellow

<script type="text/javascript" language="javascript">



function populate(oSelect) {

var opt, opt2, a=0, i = 0, textarea = document.getElementById('notes');

while (opt = oSelect.options[i++])

if (opt.selected && textarea.value.indexOf(opt.value) == -1)

textarea.value += opt.value + '\n';



return true;

}


</script>



<body>


<?php

$db_host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_db = 'dbname';

$db_link = mysql_connect($db_host, $db_user, $db_pass) or die('MySQL Connection Error:'.mysql_error());
mysql_select_db($db_db) or die('MySQL Error: Cannot select table');



$sql = "SELECT id,item,colorinfo FROM table ORDER by id";
$result = mysql_query($sql);



echo "<form name=f1 method=post action='' onSubmit='return false;'>";
echo "<select name=m1 size='8' onDblClick='populate(this)'>";
while ($row=mysql_fetch_assoc($result)) {
$id=$row['id'];
$display_name=$row['item'];
$display_color=$row['color'];
echo "<option value='$display_name'>$display_name</option>";

}


echo "</select>";
echo "<br>";

echo "<th>Color:<input type='text' name='color' id='color'>";
echo "</form>";
echo "</td>";
echo "<td valign='top' align='left'>";
echo "<form name=f2 method=post action='' onSubmit='return false;' >";
echo "<p align='left'>";


echo "</form>";

?>

</table>
<form>
<TEXTAREA class=formfield2 name="notes" id="notes" rows=12 cols=16 wrap="virtual"></TEXTAREA>
<input type="button" value="clear" onClick="if (confirm('Clear the field?'))notes.value='',">
</form>
</body>
</html>

Recommended Answers

All 2 Replies

This is not a PHP thing, plz move this 2 the Javascript forum and look for the answer there

This is not a PHP thing, plz move this 2 the Javascript forum and look for the answer there

Why it should be moved to JavaScript section? Because of that little JS script that may not be necessary at all?

PS: If you belived that post is wrong section and should be moved, you should have pressed Flag Bad Post option next to the post, not demand it to be moved by replying to the post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.