I've been on this for so long and cant seem to get it working. I am trying to display teh value of a dropdown in a text box and i've tried so many things but it just wont work:

<?php 
	$query3 = "SELECT contaminant, gac_value FROM gac_ea WHERE land_use = 'Allotment' ORDER BY id";
	$result3 = mysql_query($query3) or die(mysql_error());   
	echo "<select name=\"contaminant[]\" id=\"contaminant\" value=''></option>";
	echo "<option>Select </option>";
	while($row=mysql_fetch_array($result3)){   
	    echo "<option value=$row[contaminant]> $row[contaminant] </option>"; } 
		echo "</select></td>"; 
        echo "<td class=\"row3\">";
        echo "<input type=\"text3\" name=\"gac_value[]\" id=\"gav_value\" value=\"$row[gac_value]\" disabled=\"disabled\" /> </td>"; 
 // End contaminant loop 
	?>

Any help'll be greatly appreciated.

Sorry, I'm still waking up this morning but I did catch one error:

echo "<option value=$row[contaminant]> $row[contaminant] </option>"; }

should have quotes around the value:

echo "<option value='$row[contaminant]'> $row[contaminant] </option>"; }

That would be enough to mess your day up. :)

Thanks. Able to retrieve the options, just not able to display their corresponding gac value in a textfield.

I got it to work. Boy are you not going to like it.

It involves javascript, a sheep, and voodoo priestess.

<?php
$query3 = "SELECT contaminant, gac_value FROM gac_ea WHERE land_use = 'Allotment' ORDER BY id";
$result3 = mysql_query($query3) or die(mysql_error());


//pass gac_values to javascript array and create javascript function
$rstpack = mysql_query($query3); // I'm just doing this to minimize code alteration
$nmr=mysql_numrows($rstpack);
echo "<script type=\"text/javascript\" language=\"javascript\">";
echo "scriptAr = new Array();";
for ($i=0;$i<$nmr;$i++)
 {
 $rtpush=mysql_result($rstpack,$i,"gac_value");
 echo "scriptAr.push(\"$rtpush\");";
 }
 echo "function chForm(g){var myobj=document.getElementById(\"gac\");myobj.value=scriptAr[g];}";
echo "</script>";


echo "<select name=\"contaminant[]\" id=\"contaminant\" value='' onchange=chForm(this[selectedIndex].value>";
echo "<option>Select </option>";
$i=0;
while($row=mysql_fetch_array($result3)){
echo "<option value='$i'> $row[contaminant] </option>";
$i++; }
echo "</select></td>";
echo "<td class=\"row3\">";
echo "<input type=\"text\" name=\"gac\" id=\"gac\" value=\"\" readonly /> </td>";
// End contaminant loop
?>

You may still have to work with this some, since my code was actually:

$result=popquery("select ecfirst,style from members where level>1");
$numrow=mysql_numrows($result);
echo "<script type=\"text/javascript\" language=\"javascript\">";
echo "scriptAr = new Array();";
for ($i=0;$i<$numrow;$i++)
 {
 $rtpush=mysql_result($result,$i,"style");
 echo "scriptAr.push(\"$rtpush\");";
 }
 echo "function chForm(g){var myobj=document.getElementById(\"gac\");myobj.value=scriptAr[g];}";
echo "</script>";
echo "<select onchange='chForm(this[selectedIndex].value)'>";
for ($i=0;$i<$numrow;$i++)
 {
 $dname=mysql_result($result,$i,"ecfirst");
 echo "<option value='$i'>$dname</option>";
 }
echo "</select>";
echo "<input type='text' name='gac' id='gac' value='' readonly /><br />";

I did my best to adapt it to your code, but I bear no resposibility for non-functional status, cpu overheating, or inadvertent creation of black holes resulting from the execution of this code. :)

Thank you so much. I'll get on with it right away and let you know how it goes :)

Be a part of the DaniWeb community

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