Specify default on drop-down based on DRW?

A

Augie Dawg

I've created a page where information in a record can be modified. In a
table-resident form, I list the current value, then a drop-down which is
created by the DRW. The problem I'm trying to overcome is that the value
that shows in the drop-down is the first one returned from the database, not
the current value. I'd rather not have to force the user to respecify all
values just to change one. I know how to specify the current value as an
option when the drop-down list choices are static, but can't figure a way to
get what I need when the choices are dynamically generated. Any ideas out
there?

Thanks,
A.D.
 
J

Jim Buyens

-----Original Message-----
I've created a page where information in a record can be
modified. In a table-resident form, I list the current
value, then a drop-down which is created by the DRW. The
problem I'm trying to overcome is that the value
that shows in the drop-down is the first one returned
from the database, not the current value. I'd rather not
have to force the user to respecify all values just to
change one. I know how to specify the current value as
an option when the drop-down list choices are static, but
can't figure a way to get what I need when the choices
are dynamically generated. Any ideas out
there?

I don't believe there's a nice, easy fix for this.

For an ugly fix, try putting this at the bottom of your
form, where CategoryID is the name of the DRW-generated
drop-down list.

<script>
for (i = 0;
i < document.forms[0].CategoryID.options.length - 1;
i++) {
if (document.forms[0].CategoryID.options.value
== "<%=request("CategoryID")%>"){
document.forms[0].CategoryID.selectedIndex = i;
break;
}
}
</script>

This is *much* easier to do in ASP, and trivial in ASP.NET.

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 
A

Augie Dawg

Jim:

I did as you suggested, placing the (appropriately modified) script after
the SUBMIT button definition but before the </form> tag using the INSERT
HTML Web component, and nothing happened. I also placed the script after
the </form> tag, and that didn't work either, I'm still seeing the first
entry in the database column as opposed to the current value. Am I
misunderstanding your directions, or did I not clearly state my problem? In
case it's the latter, I'm thinking I need to be able to somehow modify the
drop-down list properties to include an entry that would show the currently
selected record first.

A.D.




Jim Buyens said:
-----Original Message-----
I've created a page where information in a record can be
modified. In a table-resident form, I list the current
value, then a drop-down which is created by the DRW. The
problem I'm trying to overcome is that the value
that shows in the drop-down is the first one returned
from the database, not the current value. I'd rather not
have to force the user to respecify all values just to
change one. I know how to specify the current value as
an option when the drop-down list choices are static, but
can't figure a way to get what I need when the choices
are dynamically generated. Any ideas out
there?

I don't believe there's a nice, easy fix for this.

For an ugly fix, try putting this at the bottom of your
form, where CategoryID is the name of the DRW-generated
drop-down list.

<script>
for (i = 0;
i < document.forms[0].CategoryID.options.length - 1;
i++) {
if (document.forms[0].CategoryID.options.value
== "<%=request("CategoryID")%>"){
document.forms[0].CategoryID.selectedIndex = i;
break;
}
}
</script>

This is *much* easier to do in ASP, and trivial in ASP.NET.

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 
J

Jim Buyens

Augie Dawg said:
Jim:

I did as you suggested, placing the (appropriately modified) script after
the SUBMIT button definition but before the </form> tag using the INSERT
HTML Web component, and nothing happened. I also placed the script after
the </form> tag, and that didn't work either, I'm still seeing the first
entry in the database column as opposed to the current value. Am I
misunderstanding your directions, or did I not clearly state my problem? In
case it's the latter, I'm thinking I need to be able to somehow modify the
drop-down list properties to include an entry that would show the currently
selected record first.

I'm posting the page I used for testing below. It uses the "Sample"
Northwind database. Extraneous line endings may keep it from working
on your system but you should get the idea.

You can't modify the drop-down list properties because the DRW
manufactures the drop-down list's HTML on the fly. That's why I had to
write JavaScript to look at the values in the completed list and set
the selectedIndex property to the one that contains the previous
value.

Are you sure you changed the name CategoryID to thE name of your
drop-down list in all four places?

<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=windows-1252">
<title>DRW Drop-Down List with Memory</title>
</head>
<body>
<form>
<nobr><!--webbot bot="DatabaseRegionStart"
s-columnnames="CategoryID,CategoryName,Description"
s-columntypes="3,202,203" s-dataconnection="Sample"
b-tableformat="FALSE" b-menuformat="TRUE"
s-menuchoice="CategoryName" s-menuvalue="CategoryID"
b-tableborder="TRUE" b-tableexpand="TRUE"
b-tableheader="TRUE" b-listlabels="TRUE"
b-listseparator="TRUE" i-listformat="0"
b-makeform="FALSE" s-recordsource="Categories"
s-displaycolumns="CategoryID,CategoryName" s-criteria
s-order s-sql="SELECT * FROM Categories"
b-procedure="FALSE" clientside suggestedext="asp"
s-defaultfields s-norecordsfound="No records returned."
i-maxrecords="256" i-groupsize="0" botid="0"
u-dblib="../_fpclass/fpdblib.inc"
u-dbrgn1="../_fpclass/fpdbrgn1.inc"
u-dbrgn2="../_fpclass/fpdbrgn2.inc"
preview=" &lt;span style=&quot;color: rgb(0,0,0); background-color:
rgb(255,255,0)&quot;&gt;Database&lt;/span&gt; "
startspan --><!--#include file="../_fpclass/fpdblib.inc"-->
<% if 0 then %>
<SCRIPT Language="JavaScript">
document.write("<div style='background: yellow; color: black;'>The
Database Results component on this page is unable to display database
content. The page must have a filename ending in '.asp', and the web
must be hosted on a server that supports Active Server Pages.</div>");
</SCRIPT>
<% end if %>
<%
fp_sQry="SELECT * FROM Categories"
fp_sDefault=""
fp_sNoRecords="No records returned."
fp_sDataConn="Sample"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=False
fp_fMenuFormat=True
fp_sMenuChoice="CategoryName"
fp_sMenuValue="CategoryID"
fp_sColTypes="&CategoryID=3&CategoryName=202&Description=203&"
fp_iDisplayCols=2
fp_fCustomQuery=False
BOTID=0
fp_iRegion=BOTID
%>
<!--webbot bot="DatabaseRegionStart" endspan
i-checksum="47909" --><select name="CategoryID" size="1">
<!--webbot bot="AspInclude" clientside
u-incfile="../_fpclass/fpdbrgn1.inc" startspan --><!--#include
file="../_fpclass/fpdbrgn1.inc"-->
<!--webbot bot="AspInclude" endspan i-checksum="56958" -->
<option value="<%=FP_FieldHTML(fp_rs,"CategoryID")%>"><%=FP_FieldHTML(fp_rs,"CategoryName")%>
</option>
<!--webbot bot="AspInclude" clientside
u-incfile="../_fpclass/fpdbrgn2.inc" startspan --><!--#include
file="../_fpclass/fpdbrgn2.inc"-->
<!--webbot bot="AspInclude" endspan i-checksum="57022" -->
</select><!--webbot bot="DatabaseRegionEnd"
b-tableformat="FALSE" b-menuformat="TRUE"
u-dbrgn2="../_fpclass/fpdbrgn2.inc" i-groupsize="0"
clientside
preview=" &lt;span style=&quot;color: rgb(0,0,0); background-color:
rgb(255,255,0)&quot;&gt;Results&lt;/span&gt; "
startspan --><!--webbot bot="DatabaseRegionEnd"
endspan --></nobr>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" name="btnSub" value="Submit">
<script>
for (i = 0;
i < document.forms[0].CategoryID.options.length - 1;
i++) {
if (document.forms[0].CategoryID.options.value
== "<%=request("CategoryID")%>"){
document.forms[0].CategoryID.selectedIndex = i;
break;
}
}
</script>
</form>
</body>
</html>

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top