1

I have this table called ost_investigadores with the next fields:

nombre, topic_id, isactive, email

I have a form with these textbox:

Nombre:
Email:

I have about 400 records and I used the following code to create a combobox displaying the names so I can select one of them instead of writing their names by hand in a text box.

<td>
    <select name="name">
    <option value="" selected ></option>
    <?
    $services= db_query('SELECT topic_id, nombre, email FROM ost_investigadores 
     WHERE isactive=1 ORDER BY nombre');
        if($services && db_num_rows($services)) {
        while (list($name,$nombre) = db_fetch_row($services)){
        $selected = ($info['name']==$name) ?'selected':''; ?>
        <option value="<?=$nombre ?>"<?=$selected?>><?=$nombre?></option>

With the above code I get a combobox or select list with a list of my users´ name and I only have to select one, now THE PROBLEM that I have is that I would like to print out or get their email value with an echo, when I choose a name from the combobox I would like to get their corresponding email.

I have tried with this code:

$services= db_query(" SELECT email FROM ost_investigadores WHERE nombre='$nombre'");
list($email) = db_fetch_row($services);
echo "$email";

but nothing happens, instead using the variable $name If I wrote the name like nombre='Jonh Smith' I get his email.

Or I would like to do something like:

$services= db_query(" SELECT email FROM ost_investigadores WHERE nombre=<option value=" <?=$nombre ?>"<?=$selected?>><?=$nombre?></option>");
list($email) = db_fetch_row($services);
echo "$email";

So , What can I do to get their email once I select a name from the list?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
  • Are yo asking about how to get the email from the name after the form has been POSTed? – Mike Brant Feb 25 '14 at 23:57
  • Not exactly, immediately when I choose a name from the selected list, before I submit it in the form, I would like to get the email value. – user3353563 Feb 26 '14 at 15:07
  • have a look at the answer here - http://stackoverflow.com/questions/5861090/populating-one-select-box-based-on-the-selection-in-another-select-box-jquery – glendaviesnz Feb 26 '14 at 18:28

0 Answers0