[thelist] re: Multiple Selects in asp / javascript

Ormerod Mark mormerod at cornwall.gov.uk
Wed Aug 25 06:05:07 CDT 2004


Thanks for your help guys - I've done it (so far!) this way :

<script language="JavaScript">
	<!--
	var arrData = new Array();
<%
intCounter = 0
SQLString="sswr_sp_getpractices;"
set RSPractices = server.CreateObject("ADODB.Recordset")
	RSPractices.Open SQLString,strconnection,2,2
do until RSPractices.EOF
            %>arrData[<%=intCounter%>] = new
Array("<%=RSPractices("PracticeLocationID")%>","<%=RSPractices("PracticeID")
%>","<%=RSPractices("PracticeDetails")%>");
            <%
            intCounter = intCounter + 1
            RSPractices.MoveNext()
loop
RSPractices.Close()
set RSPractices = nothing
%>

function BindToCombo(strTargetCmbID, varFilterValue, arrData) {
            var objTargetCmb = document.getElementById(strTargetCmbID);
            //Reset combo box options
            for(var i=(objTargetCmb.length-1);i>=0;i=i-1) {
                        objTargetCmb.options[i] = null;
            }
            var objOption = new Option("Not Known","1");
            try        //Try adding it the microsoft way first - they do
have 80% of the browser market share!
                        {objTargetCmb.add(objOption);}
            catch(err) //Try it the proper way for more compliant browsers
                        {objTargetCmb.add(objOption, null);}
            for (var i=0; i<arrData.length; i++) {
                        if (arrData[i][0] == varFilterValue) {
                                    var objOption = new
Option(arrData[i][2],arrData[i][1]);
                                    try
 
{objTargetCmb.add(objOption);}
                                    catch(err)
                                                {objTargetCmb.add(objOption,
null);}
                                    }
                        }
            }
-->
</script>

The select which trigers the filer has an onchange as follows :

<select class="StandardForm" name="PracticeLocationID"
onchange="BindToCombo('PracticeID',this.value,arrData)">

The ID being the ID of the select we're binding to.

I'd like to get an "if" statement in there so that is the option select all
(value "all") is picked I can restore the select being changed to the
original state it is in on page load (show everything).

Thanks.


***************************************************************
Important: This e-mail and its attachments are intended for the 
above-named only and may be confidential.  If they have come 
to you in error you must take no action based on them, nor must
you copy or show them to anyone;  please e-mail us immediately 
at enquiries at cornwall.gov.uk

Security Warning: Although this e-mail and its attachments have
been screened and are believed to be free from any virus, it is
the responsibility of the recipient to ensure that they are virus free.
The Authority will not accept liability for any damage caused by a virus.



More information about the thelist mailing list