Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Little help merging some ASP and JS

Status
Not open for further replies.

RhythmAddict112

Programmer
Jun 17, 2004
625
US
hey all..cFlava was nice enough to help me with an issue I had over in the JS forum. I needed a technique that would help me determine the values in drop box box B based on the selection from drop down box A. The code for this is below...The problem is, I need to populate the arrays with my values from my query.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]

<html>
<head>
<title>new document</title>

<script language="javascript" type="text/javascript">
<!--

var array_0 = new Array('Jeep', 'VW', 'Ford');
var array_1 = new Array('Giants', 'Mets', 'Rangers');
var array_2 = new Array('Pizza', 'Ice Cream', 'Beer');

function build(which_array, which_field) {
    var ary;
    if (which_array != "") {
        ary = eval('array_' + which_array);
        which_field.options.length = 0;
        for (var i = 0; i < ary.length; i++) {
            which_field.options[which_field.options.length] = new Option( ary[i], ary[i]);
        }
    }
}

-->
</script>

</head>

<body>

<form name="f">

    <select name="s1" onchange="build(this.options[this.selectedIndex].value, this.form.s2);">
        <option value="" selected>Select One...</option>
        <option value="0">Cars</option>
        <option value="1">Teams</option>
        <option value="2">Food</option>
    </select>

    <select name="s2">
    </select>

</form>

</body>

</html>

My first drop down would be doing:

SELECT Locations, zone_id
FROM tbl_locations;
[will generate a max of 709 results]


and the 2nd drop down...
select locations
from tbl_locations
where zone_id = *zone_id_from_first_drop_down*

can anyone help me out on this?
 
You will need to reload the page to do the 2nd SQL query. What I would do is add the following to the first select menu: <select onchange="javascript:document.f.action='<your current asp page name>';document.f.submit();">

Then for the 2nd drop down menu, do a check to see if request.form("s1") is null. If it isn't, populate the 2nd drop down menu via the specific sql query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top