I created a user registration page using ASP and Dreamweaver, I tried to create a drop down box filled with options from a database. I only wanted the box to contain one of each option but it contains every one, one for each user when i view this in firefox. when i view the page in explorer the box does not contain anything and the options are all listed below the box.

part of the code is underlined, when i hover over it i get an message 'The title attribute of the SELECT tag is not supported [Netscape Navigator 4.0, Netscape Navigator 6.0]' I do not know what this error means, is this why the drop down box won't work??

heres part of my code, the line in red is the line that is underlined:-

Dim rs_accesslevel
Dim rs_accesslevel_numRows

Set rs_accesslevel = Server.CreateObject("ADODB.Recordset")
rs_accesslevel.ActiveConnection = MM_dbtest_STRING
rs_accesslevel.Source = "SELECT accesslevel FROM users"
rs_accesslevel.CursorType = 0
rs_accesslevel.CursorLocation = 2
rs_accesslevel.LockType = 1
rs_accesslevel.Open()

rs_accesslevel_numRows = 0
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>register</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<h3>Please register new user below:-</h3>
<form action="<%=MM_editAction%>" method="POST" name="formregister" id="formregister">
  <table width="528" height="136" border="1">
    <tr>
      <td width="153">username</td>
      <td width="359"><input name="txtusername" type="text" id="txtusername" size="50"></td>
    </tr>
    <tr>
      <td>password</td>
      <td><input name="txtpassword" type="password" id="txtpassword" size="20"></td>
    </tr>
    <tr>
      <td>Access level</td>
      <td><select name="accesslevel" title="<%=(rs_accesslevel.Fields.Item("accesslevel").Value)%>"><input name="txtaccesslevel" type="text" id="txtaccesslevel" size="50">
        <%
While (NOT rs_accesslevel.EOF)
%>
        <option value="<%=(rs_accesslevel.Fields.Item("accesslevel").Value)%>" <%If (Not isNull((rs_accesslevel.Fields.Item("accesslevel").Value))) Then If (CStr(rs_accesslevel.Fields.Item("accesslevel").Value) = CStr((rs_accesslevel.Fields.Item("accesslevel").Value))) Then Response.Write("SELECTED") : Response.Write("")%> ><%=(rs_accesslevel.Fields.Item("accesslevel").Value)%></option>
        <%
  rs_accesslevel.MoveNext()
Wend
If (rs_accesslevel.CursorType > 0) Then
  rs_accesslevel.MoveFirst
Else
  rs_accesslevel.Requery
End If
%>

Thanks!
Any ideas gretaly apprecitated!

GLT

Dani AI

Generated

The behavior you describe is classic invalid-HTML + duplicate-data issues, and the browser differences come from each browser trying to repair the malformed DOM in its own way. correctly flagged the HTML problem; Dreamweaver’s “title” warning is a compatibility notice for very old browsers, but the real breakage is the structure of your markup and how the data is produced.

Only <option> (and <optgroup>) are allowed inside a <select> — putting an <input> there makes the document invalid and yields inconsistent rendering. Fix the structure first (put the input outside the select). Next, stop emitting duplicate option rows at the source (use a DISTINCT/Group in SQL) or dedupe while rendering. Use Server.HTMLEncode when inserting database values into attributes/text to avoid breaking the HTML.

If changing the query isn’t possible, collect unique values as you loop and emit one option per distinct value. Example VBScript pattern (collect unique strings, HTML-encode output, and mark the selected item based on Request.Form or a default variable):

<%
Dim seen, val, selected
Set seen = Server.CreateObject("Scripting.Dictionary")
selected = Request.Form("accesslevel") ' or your default

Do While Not rs.EOF
  val = CStr(rs("accesslevel"))
  If Not seen.Exists(val) Then
    seen.Add val, 1
    Response.Write "<option value=""" & Server.HTMLEncode(val) & """"
    If val = selected Then Response.Write " selected"
    Response.Write ">" & Server.HTMLEncode(val) & "</option>"
  End If
  rs.MoveNext
Loop
Set seen = Nothing
%>

For a typed “combo” UX, consider HTML5 <datalist> or a JS autocomplete widget instead of trying to nest controls. See MDN for the <select> element and <datalist> for current behavior and allowed content: select and datalist.

Quick checklist: remove nested input, ensure unique data (SQL or server-side), HTML-encode values, use the right recordset cursor if you need repositioning, and always close/free ADO objects.

Recommended Answers

All 4 Replies

2 things:

1. Title is not a w3c standardized attribute for the SELECT tag. Don't use it
http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.6

2. You have an INPUT tag nested into your SELECT tag

<td><select name="accesslevel" title="<%=(rs_accesslevel.Fields.Item("accesslevel").Value)%>">[B]<input name="txtaccesslevel" type="text" id="txtaccesslevel" size="50">[/B]
        <%

Move this above or below the SELECT closing tag

Hi, Thanks for getting back to me.

I moved the input line above and below the select bit but that just created an input box above or below the drop down box depending where i put it.

Any other ideas?? or where exactly do you mean to put it??

Thanks!

GLT

Perhaps I may be confused with the question, but the SELECT element is a dropdown list by nature. The INPUT element is another form element and the inclusion of it within the SELECT element is why you are seeing odd results. I'm thinking you are trying to make a combo box. I'd really just remove it alltogether.

If you are looking to make a combo box where you type and find the item in a list, that's a different story and would require different code. Presumably, you would want to place the INPUT element directly above the SELECT element, but you would require JavaScript events to search the list. You would also need DHTML if you wanted the list to open and close like a combo box.

I forgot one other item in the previous post. Use the DISTINCT qualifier in your SQL statement to avoid the duplicate entries. rs_accesslevel.Source = "SELECT [B]DISTINCT[/B] accesslevel FROM users"

try following

<td><input value="<%=(rs_accesslevel.Fields.Item("accesslevel").Value)%>" name="txtaccesslevel" type="text" id="txtaccesslevel" size="50">
<select name="accesslevel">
        <%
While (NOT rs_accesslevel.EOF)
%>
        <option value="<%=(rs_accesslevel.Fields.Item("accesslevel").Value)%>" <%If (Not isNull((rs_accesslevel.Fields.Item("accesslevel").Value))) Then If (CStr(rs_accesslevel.Fields.Item("accesslevel").Value) = CStr((rs_accesslevel.Fields.Item("accesslevel").Value))) Then Response.Write("SELECTED") : Response.Write("")%> ><%=(rs_accesslevel.Fields.Item("accesslevel").Value)%></option>
        <%
  rs_accesslevel.MoveNext()
Wend
%>
</select>
<%
If (rs_accesslevel.CursorType > 0) Then
  rs_accesslevel.MoveFirst
Else
  rs_accesslevel.Requery
End If
%>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.