Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ASP / Database Access / April 2008



Tip: Looking for answers? Try searching our database.

Updating records with form field type 'select'

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael S - 03 Apr 2008 23:48 GMT
I'm retrieving records from my db and update them.  Text fields are no
problem, but when it comes to different types of fields, such as 'select'
fields with options the default in the option list is the first item in the
list and not the actual database record.

For example, this text field is fine.  It retrieves city and puts it into
the form:

<input name="city" type="text" class="formfield" id="city"
value="<%=rs("city")%>" size="50">

But this select field is not.  Although the selelct choice saves to the db,
the display in the users edit form is the first record in the select list.  
I'm not sure how to make it display the record from the db.

<select name="stateprov" class="formfield" id="stateprov"
value="<%=rs("stateprov")%>">
                                         <option>Alabama</option>
                                         <option>Alaska</option>
</select>

Any help is much appreciated!!!
Daniel Crichton - 04 Apr 2008 13:24 GMT
Michael wrote  on Thu, 3 Apr 2008 15:48:02 -0700:

> I'm retrieving records from my db and update them.  Text fields are no
> problem, but when it comes to different types of fields, such as
> 'select'
> fields with options the default in the option list is the first item in
> the  list and not the actual database record.

> For example, this text field is fine.  It retrieves city and puts it
> into  the form:

> <input name="city" type="text" class="formfield" id="city"
> value="<%=rs("city")%>" size="50">

> But this select field is not.  Although the selelct choice saves to the
> db,  the display in the users edit form is the first record in the
> select list.
> I'm not sure how to make it display the record from the db.

> <select name="stateprov" class="formfield" id="stateprov"
> value="<%=rs("stateprov")%>">
>                                           <option>Alabama</option>
>                                           <option>Alaska</option>
> </select>

> Any help is much appreciated!!!

You need to add a "selected" attribute to the option, not set the value of
the select tag.

eg.

<select name="stateprov" class="formfield" id="stateprov">
                                          <option <%if rs("stateprov") =
"Alabama" then%>selected<%end if%> >Alabama</option>
                                          <option <%if rs("stateprov") =
"Alaska" then%>selected<%end if%>>Alaska</option>
</select>

although this isn't very easy to code up with a long list. If your list is
db generated, then you could do something like this:

assuming rsProv is a recordset holding the provinces in a column called
"prov"

<select name="stateprov" class="formfield" id="stateprov">
<%
do until rsProv.EOF
   if rs("stateprov") = rsProv("prov") then
       sSelected = " selected"
   else
       sSelected = ""
   end if
%>
                                         <option
<%=sSelected%>><%=rs("stateprov")%></option>
<%
   rsProv.MoveNext
loop
%>
</select>

Signature

Dan

Michael S - 04 Apr 2008 15:56 GMT
Thanks for the assistance!

> Michael wrote  on Thu, 3 Apr 2008 15:48:02 -0700:
>
[quoted text clipped - 57 lines]
> %>
>  </select>
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.