Here’s my problem.
I have a mysql database (name) which helds 3 fields, id, naam, email. In php I’ve made the connection and create a selection menu and with javascript I was able to display, (when I selected for example “Bas” in the selection menu), bas his name into a first input text field. Now a couple of things I still want but can’t seem to get it right.
First: I also want to display “bas” his email address in a second input text field. (the database contains more names, but this an example).
Second: The selection menu starts with the first name in the database, but can I make it for example “Select name” as beginning.
Here is the code I have for now, please help.
[CODE]
<script>
function setVal()
{
document.getElementById(‘naam’).value = cArray[document.getElementById(‘name’).selectedIndex];
}
var cArray = new Array();
</script>
<!– Contact info –>
<table border=”0″ width=”100%”>
<tr>
<td style=”text-align:right” width=”150″><?php echo $hesklang[‘select_name’]; ?>: <font class=”important”>*</font></td>
<td width=”80%”>
<?php
require(HESK_PATH . ‘inc/database.inc.php’);
hesk_dbConnect();
$sql = ‘SELECT naam,email FROM `’.$hesk_settings[‘db_pfix’].’names`’;
$result = hesk_dbQuery($sql) or die (‘Error in query: $query. ‘ . mysql_error());
echo “<select id=”name” name=”name” onChange=”javascript:setVal();”>”;
// keeps getting the next row until there are no more to get
$Cnt=0;
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a dropdown
echo “<option value=’$row[naam]’>$row[naam]</option>”;
//Adding to Array
echo “<script>cArray[$Cnt]=’$row[naam]’;</script>”;
$Cnt++;
}
echo “</select>”;
?>
</td>
</tr>
<tr>
<br>
<td style=”text-align:right” width=”150″></td>
<td width=”80%”><input type=”text” name=”naam” id=”naam” size=”40″ maxlength=”30″ value=”<?php echo stripslashes(hesk_input($_SESSION[‘c_name’]));?>” /></td>
</tr>
<tr>
<td style=”text-align:right” width=”150″></td>
<td width=”80%”><input type=”text” name=”email” id=”email” size=”40″ maxlength=”50″ value=”<?php echo stripslashes(hesk_input($_SESSION[‘c_email’]));?>” /></td>
</tr>
</table>