Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms 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 February 23rd, 2005, 02:50 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 106
Thanks: 0
Thanked 0 Times in 0 Posts
Default multiple drop down inconsistency

I have a form with three drop-down lists.

The first one is hardcoded.

The other two are dynamically dependant. In other words when selecting a category from the second drop-down the third popuates with its relative content.

My problem is when those two drop-downs are "loaded", The first one (Hard coded) refreshes to the first item in the list. I would like it to remember that first selection and not refresh. Is this possible, and if so how.

Thanks again,
nancy
 
Old February 24th, 2005, 03:48 AM
Authorized User
 
Join Date: Aug 2004
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I believe you are submitting the page when the second drop down is selected. Is it so?

One way to deal this is have a check before every <option> in the select box.



Shibu Narayanan
Software Associates
 
Old February 28th, 2005, 06:10 AM
Authorized User
 
Join Date: Dec 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you can fill combo boxes dynamically without submitting the page using java script arrays. try with below code.

<%
    dim con,rsCatg,catgCnt,rsProducts,prodCnt

    set con=server.CreateObject("adodb.connection")
    set rsCatg=server.CreateObject("adodb.recordset")
    set rsProducts=server.CreateObject("adodb.recordset")

    con.ConnectionString ="provider=sqloledb.1;data source=astrodev;initial catalog=northwind;user id=sa;pwd=sa"
    con.Open
    rsCatg.Open "select * from categories where categoryid=5 or categoryid=6",con,3
    rsProducts.Open "select * from products where categoryid=5 or categoryid=6 order by categoryid,productid",con,3
    catgCnt = rsCatg.RecordCount
    prodCnt = rsProducts.RecordCount
%>


<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>

<BODY>
<script language=javascript>
var catgindx,prodindx;
catgindx =0;
prodindx=0;

var catgarr=new Array(<%=catgCnt%>);
for(k=0;k<=<%=catgcnt%>;k++)
    catgarr[k]=new Array();


    <%dim tempcatgid
        tempcatgid=rsProducts("categoryid")
    for i=0 to rsProducts.RecordCount-1
        if cstr(tempcatgid)<> cstr(rsProducts("categoryid")) then
            tempcatgid=rsProducts("categoryid") %>
            catgindx=catgindx+1
            prodindx=0;
        <%end if%>

        //alert('product id:' + '<%=rsProducts("productid")%>')
        catgarr[catgindx][prodindx]=new Option("<%=rsProducts("ProductName")%>",'<%=rsProd ucts("productid")%>');
        prodindx=prodindx+1;

    <%rsProducts.movenext
    Next%>


    function fillProducts()
    {

        var catgid;
        catgid=document.frmpost.cmbCatg.selectedIndex ;
        catgid=catgid-1;
        if(document.frmpost.cmbCatg.selectedIndex==0)
        {
            for(i=0;i<document.frmpost.cmbProd.options.length; i++)
                document.frmpost.cmbProd.options[i+1]=null
        }

        for (i=0;i<catgarr[catgid].length;i++)
        {
            document.frmpost.cmbProd.options[i+1]=new Option(catgarr[catgid][i].text,catgarr[catgid][i].value)
        }
        document.frmpost.cmbProd.options[0].selected=true

    }

</script>

<form name=frmpost method=post>
    <select name=cmbCatg onchange="javascript:fillProducts();">
        <option value=0>- -Select Category- -</option>
    <% While not rsCatg.EOF %>
        <option value=<%=rsCatg(0)%>><%=rsCatg(1)%></option>
    <% rsCatg.MoveNext
        Wend%>
    </select>

    <select name=cmbProd>
        <option value=0>- -Select Product- -</option>
    </select>

</form>


</BODY>
</HTML>







Similar Threads
Thread Thread Starter Forum Replies Last Post
Fig 3-12 inconsistency laurentpomata BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 2 February 7th, 2009 03:30 PM
Selecting from multiple drop-lists Earl Hickey SQL Language 4 July 9th, 2008 03:34 PM
data inconsistency baties General .NET 0 August 27th, 2007 10:44 AM
Please Help me with Drag-n-Drop of multiple items vb_programmer Pro VB 6 9 October 7th, 2006 01:56 AM
Complex Multiple Drop-Down Script phungleon Javascript 2 September 20th, 2005 08:34 AM





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