Jump to content

Get the value from DropDown box and paste it in Textbox

- - - - -

  • Please log in to reply
1 reply to this topic

#1
NumOne

NumOne

    Newbie

  • Members
  • Pip
  • 9 posts
Hi

In the following code, I am trying to get the value from the dropdown box and show it in the textbox

<html>

<body>

<title>Num One Website</title>


<?

$con = mysql_connect("mysql17.000webhost.com","a6395791_nasser","11a12a13a");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}


mysql_select_db("a6395791_StMarks", $con);


$result1 = mysql_query("SELECT * FROM Students") ;


echo "<FORM>";

echo "<select id='userid' name='userid' onchange='this.form.elements['showuserid'].value=this.options[this.selectedIndex].value'>";


while($row1 = mysql_fetch_array($result1)) 

{ 

echo "[COLOR="red"]<option value='".$row1['ID']."'>".$row1['ID']."</option>[/COLOR]"; 

$count = $count + 1;

} 

echo "</select>"; 

echo "</FORM>";

mysql_close($con);

?>


<form action="ConfirmEnter.php" method="post">

<p>[COLOR="red"]<input id="showuserid" name="showuserid" readonly="readonly" size=5/>[/COLOR]<input type="text" name="name" /><input type="text" name="mt" size=5 value="0.0"/><input type="text" name="pr" size=5 value="0.0" /><input type="text" name="fi" size=5 value="0.0" /><input type="text" name="tot" size=5 /></p><br><br>

</form>


</body>

</html>



Thank you

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Can you not just print $row1['ID'] in the value field of the input?

<input id="showuserid" name="showuserid" readonly="readonly" value="<?= $row1['ID'] ?>"size=5/>

If you mean on the client with Javascript, this is not really a job for PHP.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users