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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dependent droplists

Status
Not open for further replies.

unreal1969

Programmer
Dec 7, 2003
9
0
0
CA
I need to create 10 sets of 2 dependent drop lists one for manufacturers and one for brands now when a manufacturer is chosen to populate the brand droplist with brands coresponding to that selected manufacturer now how can i acomplish this with out quering the database 10 times
I'm new at this so if it's not to much trouble can you give a little bit of code

thanx for the help
aj
 
do you have experience with javascript objects?

This could be very helpful as you could create dependencies with arrays inside the object.
Gary Haran
 
No i don't have alot of knowledge on js objects can you still help me?
 
Ok this is a starting point. However creating the dependencies will take a little bit more time and doing a hierarchical setup might be hard. It's a bit late in my time zone but I hope I can at least give you a good start with this. You may need to be ingenuous with your variable names and what not so you could simply rely on that to script your dependencies. I'll be back on monday to see what people have to add. Maybe someone could take this code and make it a marvel (it sure ain't yet).


<html>
<head>
<script>

function mySelectRoot()
{
this.optionsItems = new Array()

this.add = function (txt, val)
{
this.optionsItems[this.optionsItems.length] = new Option(txt, val)
}

this.feed = function(formSelect)
{
for (var i = 0; i < this.optionsItems.length; i++)
{
formSelect[formSelect.length] = this.optionsItems
}
}
}

function start()
{
var selectFiller = new mySelectRoot()
selectFiller.add(&quot;one&quot;, &quot;1&quot;)
selectFiller.add(&quot;two&quot;, &quot;2&quot;)
selectFiller.add(&quot;three&quot;, &quot;3&quot;)
selectFiller.add(&quot;four&quot;, &quot;4&quot;)
selectFiller.add(&quot;five&quot;, &quot;5&quot;)

selectFiller.feed(document.testForm.testSelect)

}

function setNextSelect(obj)
{
alert(&quot;now we can set the next select to be whatever we want depending on this : &quot; + obj.options[obj.selectedIndex].text)
}

</script>
</head>

<body onload=&quot;start()&quot;>

<form name=testForm>
<select name=testSelect onchange=&quot;setNextSelect(this)&quot;>
</select>
</form>

</body>
</html>

Hope this helps you. Gary Haran
 
thanx I'll see if i could do something with this
will this work if the droplists will be populated from a sql recordset?
 
I recommend putting all the information in the start() function rather than in the select boxes. This way you have a central area where the information is.

And yes you can certainly make it work with server side information.

What technology will you be using on the server side? Gary Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top