Hi all,
I have a problem with javascript function. I already do a dynamic dropdown menu where user have to select a company name at dropdown. And after select the company name, an email address will appear in textbox.
The company table consists of Id, comp_name, email_add fields.
But I don't know the javascript to call the value of the dropdown. Below is the code that I have done:
<?
$query="SELECT * FROM company";
$result3 = mysql_query ($query); ?>
<select name="company_name" id="company_name" class="formfield" onChange="showEmail();">
<option value="">Please Select</option>
<? while($row=mysql_fetch_array($result3))
{ $c_id = $row['Id'];
$company_name=$row['company_name']; ?>
<option value="<? echo $c_id; ?>"><? echo $company_name; ?></option>
<? } ?>
</select>
<?php $c_id=$_POST['c_id']; $sql="SELECT * FROM company WHERE Id=$c_id";
$r = mysql_query($sql);
while($row=mysql_fetch_array($r))
{ $email_add = $row['email_add'];
echo "<input name='email_add' id='email_add' type='text' size='40' value='$email_add'>";
}
But I don't know how to call the function showEmail() with the selected id. I have try this:
function showEmail(){
id=document.getElementById("company_name").value;
if (id==""){
document.getElementById("email_add").value="";
return;
}
else {
document.getElementById("email_add").value;
}
}
so the situation in the system is when user select the company name at dropdown, email address will be appear in a textfield name "email_add" without submit button. Can anyone help me with the javascript?
Thank you.