Link to home
Start Free TrialLog in
Avatar of Redbirdofthesouth
Redbirdofthesouth

asked on

Populating a drop down box with values from a database

Okay so I can create a delightful little recordset full of the values I want for my drop down box but how do I get the little buggers IN the drop down box? Code examples would help me best. Thanks!
ASKER CERTIFIED SOLUTION
Avatar of allahabad
allahabad

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of arisadrian
arisadrian

<script>
var selectedValue = dropdownName{dropdownName.selectedIndex].value;

alert("value of selectedValue is :  " + selectedValue);
</script>

I think this is what you need...
just a little correction...  sorry...

<script>
var selectedValue = dropdownName[dropdownName.selectedIndex].value;

alert("value of selectedValue is :  " + selectedValue);
</script>

I think this is what you need...
however, if you are using a <form> tag, you just need to consider the form name of your drop down...

<script>

function functionName()
{
    var selectedValue = document.formName.dropdownName[document.formName.dropdownName.selectedIndex].value;

    alert("value of selectedValue is :  " + selectedValue);

}

</script>

good luck...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Redbirdofthesouth

ASKER

Thanks, you guys are great! I can't wait to put it into practice.
I'll let you know if I have any other issues.
Yes, kennethxu . I missed starting tag <td> in first cell, and in the next cell missed closing tag </td> .

Here is the revised one.

<table > 
             
                 
               <tr><td>Values </td>
                     
                  <td><select name="ListOfValues" maxlength="10">
                                 
                         <%
                             // result is the ResultSet retrived from DB
                             while (result.next()){
                               
                                // display value of the first column in the SELECT statement
                                String valueFromDB = result.getString(1);
                         %>          
                                <option value="<%=valueFromDB %>">"<%=valueFromDB %>"
                             }
                    </select>
                    <%
                             result.close();
                    %>
                   </td>      
              </tr>
             
  </table>
you should also put "}" in scriptlet.
I have searched and searched and I can't find the second part to this: What if I need to have multiple values in the select values: Like each item is Last Name, First Name.

And then, what if I want to include a value like Name_ID and have it be invisible?

Any ideas?
<option value="<%=nameID %>"><%=firstName%> <%=lastName%></option>
Avatar of girionis
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Split points between allahabad and kennethxu

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer