• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1398
  • Last Modified:

HTML List Box - Insert OPtion values on the fly

I am new to html and asp. I have a list box control (if that's what it is) with options. I am wondering if there is a way to make the content of an "options list" dynamic such that I can have a list be comprised of elements I get from a table in a db.  For example, below could I have "Honda" in a variable and have it placed
in list for pulldown at run time?


<td style="width: 10%; height: 50%;" class="style1" valign="top">
            <select style="font-size:20px;font-family:Arial; height: 42px;" size="1" name="Car Brand">
               <option selected="">Honda</option>
               <option>Toyota</option>
               </select>&nbsp;<p align="center"></td>
0
smmsmm57
Asked:
smmsmm57
  • 5
  • 2
  • 2
1 Solution
 
bugs021997Commented:
<select name="dropDownName" style="FONT-SIZE:8pt" style="border: 1px solid #808080">
<%
strSQL = "select * from TABLENAME Where CONDITION"

'OPEN RECORDSET AND EXECUTE THE QUERY

      do while not objRs.EOF
%>

<option value='<%=objRs.fields("FIELD1")%>' >      <%=objRs.fields("FIELD1")%></option>
<%
objRs.movenext
      loop
end if
%>
</select>
0
 
smmsmm57Author Commented:
I do not understand why

<option value='<%=objRs.fields("FIELD1")%>' >      <%=objRs.fields("FIELD1")%></option>


should not be

<option value='<%=objRs.fields("FIELD1")%>' >     


is that a typo mistake? thanks
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bugs021997Commented:
Nope....thats not a typo.....

The value attribute of the <option> tag sets the value that needs to be passed on if the that particular value is selected.......

<option value='<%=objRs("FIELD1")%>' > <%=objRs("FIELD1")%></option>
             ^^^^^^^^^^^^^^^^^^            ^^^^^^^^^^^^^^
             SETS THE VALUE FOR THE OPTION    This is what is displayed to the user...
             TO BE SELECTED....


Check the below example....

<select name="Bugs">
<option value="One">FirstOption</option>
<option value="Second">SecondOption</option>
</select>


Here users sees FirstOption and SecondOption as the DROPDOWN Values but what is passed to the next page or database would be One and Second respectively...

Hope this helps you
0
 
smmsmm57Author Commented:
OK...what you told me is excellent and it does answer my original question but let me ask you one little thing more.....I have a variable that I am able to display contents of in an alert() call but when I try to plug it into option stmt (see below) I gte an "object required" error....


<option value='<%=top.header.g_strTest%>' ><%=top.header.g_strTest%></option>

alert('sssss ' + top.header.g_strTest);


(displays the text contents of the variable)
0
 
BadotzCommented:
top.header.g_strTest is vlient-side, <%...%> is server side. The server knows nothing of top.header.g_strTest.
0
 
BadotzCommented:
vlient should be client, of course...not enough coffee this AM ;-)
0
 
bugs021997Commented:
Thats because <%=top.header.g_strTest%> is a ASP Variable which cannot be referenced in Javascript in that fashion.....


<SCRIPT LANGUAGE="JAVASCRIPT">
function fetchRecord(form){

alert(document.form.test.value);
}
</SCRIPT>

<FORM NAME="form" ACTION="new_page_1.htm" METHOD="post" onSubmit="return fetchRecord(this)">
<select name="test">
<option value="TEST">TEST</option>
<option value="TEST2">TEST2</option>
<input type="submit">
</form>
0
 
bugs021997Commented:
Glad i was some help to you, cheers


BUGS
^_^
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now