Hello
I am trying to populate some input text boxes from a database based on a selection from a drop down menu which is dynamically populated from the same database.
I have a function in the head section of the page:
<script type="text/javascript">
<!--
function update(this)
{
var this = document.form.NameN.value
document.write.TruckN.this
document.write.TrailerN.this
document.write.PhoneN.this
}
//-->
</script>
and in the body:
<?php
$username="*";
$password="*";
$database="drivers";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM drivers order by Name";
$result=mysql_query($query);
$num=mysql_numrows($result);
while ($row = mysql_fetch_object($result)){
$NameN = $row -> Name;
$MENU[$NameN]['TruckN'] = $row -> Truck;
$MENU[$NameN]['TrailerN'] = $row -> Trailer;
$MENU[$NameN]['PhoneN'] = $row -> Phone;
}
mysql_free_result($result);
mysql_close();
?>
<tr class="bodyClass">
<td><div align="center">
<form name="form" method="post" action="editdriver1.php">
<?php
echo "<select id=\"NameN\" name=\"NameN\" onchange=\"update(this)\" class=\"a_class\">\n";
echo "<option value=\"0\" selected >Choose a driver</option>\n";
foreach ($MENU as $_KEY => $_VAL){
echo "<option value=\"".$_KEY."\">".$_KEY."</option>\n";
}
echo "</select>\n";
?>
</div></td>
<td><div align="center">
<input name="TruckN" id="TruckN" type="text" value="" class="a_class" />
</div></td>
<td><div align="center">
<input name="TrailerN" id="TrailerN" type="text" value="" class="a_class" />
</div></td>
<td><div align="center">
<input name="PhoneN" id="PhoneN" type="text" value="" class="a_class" />
</div></td>
</tr>
</table>
<p> </p>
<table width="20%" border="0">
<COLGROUP span="2" width="0*">
<tr>
<td><div align="center">
<input type="submit" class="bUgi" name="Update" value="Update">
</form>
The drop-down menu is populated correctly and the page looks as expected, but when i make a selection nothing happens. I am not sure if the problem is with the javascript or with the php part, but i decided to post here. Help anyone?
I am trying to populate some input text boxes from a database based on a selection from a drop down menu which is dynamically populated from the same database.
I have a function in the head section of the page:
<script type="text/javascript">
<!--
function update(this)
{
var this = document.form.NameN.value
document.write.TruckN.this
document.write.TrailerN.this
document.write.PhoneN.this
}
//-->
</script>
and in the body:
<?php
$username="*";
$password="*";
$database="drivers";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM drivers order by Name";
$result=mysql_query($query);
$num=mysql_numrows($result);
while ($row = mysql_fetch_object($result)){
$NameN = $row -> Name;
$MENU[$NameN]['TruckN'] = $row -> Truck;
$MENU[$NameN]['TrailerN'] = $row -> Trailer;
$MENU[$NameN]['PhoneN'] = $row -> Phone;
}
mysql_free_result($result);
mysql_close();
?>
<tr class="bodyClass">
<td><div align="center">
<form name="form" method="post" action="editdriver1.php">
<?php
echo "<select id=\"NameN\" name=\"NameN\" onchange=\"update(this)\" class=\"a_class\">\n";
echo "<option value=\"0\" selected >Choose a driver</option>\n";
foreach ($MENU as $_KEY => $_VAL){
echo "<option value=\"".$_KEY."\">".$_KEY."</option>\n";
}
echo "</select>\n";
?>
</div></td>
<td><div align="center">
<input name="TruckN" id="TruckN" type="text" value="" class="a_class" />
</div></td>
<td><div align="center">
<input name="TrailerN" id="TrailerN" type="text" value="" class="a_class" />
</div></td>
<td><div align="center">
<input name="PhoneN" id="PhoneN" type="text" value="" class="a_class" />
</div></td>
</tr>
</table>
<p> </p>
<table width="20%" border="0">
<COLGROUP span="2" width="0*">
<tr>
<td><div align="center">
<input type="submit" class="bUgi" name="Update" value="Update">
</form>
The drop-down menu is populated correctly and the page looks as expected, but when i make a selection nothing happens. I am not sure if the problem is with the javascript or with the php part, but i decided to post here. Help anyone?