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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
just a little correction... sorry...
<script>
var selectedValue = dropdownName[dropdownName. selectedIn dex].value ;
alert("value of selectedValue is : " + selectedValue);
</script>
I think this is what you need...
<script>
var selectedValue = dropdownName[dropdownName.
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.dropdown Name[docum ent.formNa me.dropdow nName.sele ctedIndex] .value;
alert("value of selectedValue is : " + selectedValue);
}
</script>
good luck...
<script>
function functionName()
{
var selectedValue = document.formName.dropdown
alert("value of selectedValue is : " + selectedValue);
}
</script>
good luck...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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>
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.
ASKER
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?
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>
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
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
var selectedValue = dropdownName{dropdownName.
alert("value of selectedValue is : " + selectedValue);
</script>
I think this is what you need...