I have scoured the google searches and haven't run across an answer to this question.
I have a Select field that gets values from a database. That part works fine.
The database contains four fields: specialistid, name, cell, email
I would like for the user to select from a dropdown select and then have the phone and email appear in text boxes below. (I used input text boxes hoping that would make it easier on JS.)
Here is the JS:
<script>
function DeliveryFormSpecialistInfo() {
var mspecialist = document.getElementsByName("mspecialist").item(0);
var mengphone = document.getElementsByName("mengphone").item(0);
var mengemail = document.getElementsByName("mengemail").item(0);
mengphone.value = mengphone;
mengemail.value = mengphone;
}
</script>
Here is the PHP code to set it all up:
<fieldset><legend> Specialist Information </legend>
<table>
<tr>
<td><label>Specialist:</label></td>
<td>";
$query = "select * from specialist order by name";
$result = $pdo->query($query);
$TBlock .= "
<select name='mspecialist' required>";
// If no specialist selected, prompt for one
if (empty($mspecialist)) $TBlock .= "<option value = '0'>Select a Specilist</option>";
while ($row = $result->fetch()) {
$mspecialistid = $row['specialistid'];
$mengineer = $row['name'];
$mengphone = $row['cell'];
$mengemail = $row['email'];
if ((!empty($mspecialist)) && ($mspecialist == $row['specialistid'])) {
$TBlock .= "<option selected = 'selected'>".$mengineer;
}else{
$TBlock .= "<option>".$mengineer;
}
$TBlock .= "</option>";
}
$TBlock .= "
onChange='DeliveryFormSpecialistInfo()'</select>
</td>
</tr>
<tr>
<td><label>Cell Phone #:</label></td>
<td><input type='text' name='mengphone' id='mengphone' value='$mengphone' readonly</td>
</tr>
<tr>
<td><label>E-mail:</label></td>
<td><input type='text' name='mengemail' id='mengemail' value = '$mengemail' readonly></td>
</tr>
</table>
</fieldset>