Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas, linux raid resync after reboot, bind-address mysql multiple, sanibleone xxxx, ftp://192.168.100.100/, www.xxxcon

Links

XODOX
Impressum

#1: Updating records with form field type "select"

Posted on 2008-04-04 00:48:02 by Michael S

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!!!

Report this message

#2: Re: Updating records with form field type "select"

Posted on 2008-04-04 14:24:13 by Daniel Crichton

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>

--
Dan

Report this message

#3: Re: Updating records with form field type "select"

Posted on 2008-04-04 16:56:04 by michaels

Thanks for the assistance!

"Daniel Crichton" wrote:

> 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>
>
> --
> Dan
>
>
>

Report this message