Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 25th, 2008, 08:55 AM
Authorized User
 
Join Date: Aug 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Populate the 2nd drop down based on value of 1st

Hi All,

I am trying to populate the second drop down based on selection of first dropdown value. I am facing an error at second query("select ApplicationDetail from Pega_Application_Group where ApplicationGroup='"& rst(0) &"/'"
).
The same query fetches records when run in Ms-Access database, while in the code it fetches zero records.

Please help.


<SCRIPT LANGUAGE="JavaScript">
function disp_text(form1)
        {
                ctr1 = 0;

                var programarray = new Array();
                var menuarray = new Array();
                var s1;
                <%
                ssql = "select distinct ApplicationGroup from Pega_Application_Group"
                set rst = cnx.execute(sSql)
                if not rst.eof then
                i=0
                    do while not rst.eof
                %>
                programarray[<%=i%>] = "<%=rst(0)%>";

                <%
                    dim strmenu,posval1

ssql1 ="select ApplicationDetail from Pega_Application_Group where ApplicationGroup='"& rst(0) &"/'"
                    set rrst = server.createobject("adodb.recordset")
                    rrst.open ssql1, cnx


                    strmenu = ""

                    if not rrst.eof then


                        do while not rrst.eof
                        posval1 = rrst.fields.item(0).value
                        strmenu = strmenu & "/'" & posval1 & "/'" & ","
                            rrst.movenext
                        loop
                    end if
                    %>

                        menuarray[<%=i%>] = [<%=strmenu%>];

                <%
                    i = i + 1
                    rst.movenext
                    loop
                end if
                rst.close
                set rst = nothing

                %>



                for (ctr=0; ctr < programarray.length; ctr++)
                {

                    if (form1.options[form1.selectedIndex].text == programarray[ctr])
                    {

                        ctr1 = ctr1 + 1;
                        break;
                    }
                }
                var buf2=document.appsForm.AppDetail;
                var buf2arr=buf2.options;

                if (ctr1 == 0)
                {


                    buf2arr[0].value='';
                    buf2arr[0].text='---Select---';

                }
                else
                {

                    buf2arr.length=0;
                    buf2arr.length=1;
                    buf2arr.length=menuarray[ctr].length;

                    for(i=0;i < menuarray[ctr].length-1;i++)
                    {

                        var newvar1 = menuarray[ctr][i];
                        var newvar = newvar1.split("-");
                        buf2arr[(i)].value = newvar[0];
                        buf2arr[(i)].text = newvar[1];
                    }

                }
            }

</SCRIPT>


 
Old August 25th, 2008, 02:01 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

You are committing one of the cardinal sins of ASP (or PHP or JSP or ASP.NET or...) programming: You are creating an inner recordset during a loop through an outer recordset. Your server-side performance will be horrible.

So, rather than try to wade through and fix your code, I'll just post my own version of the code to do this.

http://www.clearviewdesign.com/clear...bie/demos.html

There are two versions on that page:

Multiple drop-down lists, subcategories via ASP
and
Multiple drop-down lists, subcategories via JavaScript.

The latter matches (in effect, but not in implementation) what you are doing. But no nested loops.

&&&&&&&&&&&&&&&

I do have to ask, though, why you have the / in that code:
   " WHERE ... ApplicationGroup='"& rst(0) &"/'"
???

Do you really have slashes in your DB data? Seems like a bad idea. Normally, you would have the foreign key value in table 2 *exactly* match the primary key value in table 1.
 
Old August 26th, 2008, 01:34 AM
Authorized User
 
Join Date: Aug 2008
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

With reference to your code, your code submits to itself, whereas i am trying to apply these changes within the frames and the page is not submitted here.

Could you advice on this?

The " / " in that code is to avoid the error thrown by javascript when passing the string within '....' as javasciprt identifies " ' " as end of string.


Please help.

 
Old August 26th, 2008, 12:42 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

 
Quote:
quote:The " / " in that code is to avoid the error thrown by javascript when passing the string within '....' as javasciprt identifies " ' " as end of string.


No, it doesn't. When you enclose a single quote in double quotes
   "'"
or a double quote in single quotes
   '"'
JavaScript behaves correctly.

But in any case, if you want to "escape" a character in JavaScript, you use a *BACKSLASH* character, not a forward slash.

And, finally, that code with the "/'" is *NOT* JavaScript! It is VBScript code. JavaScript would never *SEE* that string, at all, as it is used by your VBScript code to create a recordset on the server.

***************

Yes, my code posts back to itself. If you are talking about the
     Multiple drop-down lists, subcategories via ASP
version. But that's not the version you should have looked at. The demo titled
     Multiple drop-down lists, subcategories via JavaScript.
is the one that matches closely what you are doing.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate the drop down ashraf.khan Struts 2 August 2nd, 2006 03:06 AM
Populate field names upon selection from 1st DDL? InsouciantCoquette Classic ASP Databases 0 February 26th, 2006 11:23 PM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
Populating Drop Down based on other drop down jeffbarclay Java Databases 1 November 7th, 2003 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.