473,385 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Populating Second Listbox

Hi,

I have a list box which displays countries names and a second listbox
which displays their cites (based on the selection made in ListBox 1)

If the user selects USA i want to display cities in the States - if the
user selects multiple countries I want to display the cities in ALL the
selected counties e.g. a user select US and England, the second list
would display ally cities in England and all the cities in the US.

I am new to javascript so would appreciate any help.

Jul 3 '06 #1
8 2517
Hi!

I solved a similar situation like this: When user picks an item in
lstCategory, lstItemDetail will be populated by:

With Me!lstItemDetail
.RowSource = ""
.ColumnCount = 4
.ColumnWidths = "0cm;7cm;2cm;0cm"
.BoundColumn = 1
.RowSource = "SELECT ItemID,ItemName,ItemPrice,CategoryID " _
& "FROM tblItems " _
& "WHERE (((CategoryID) = Forms!frmItems!lstCategory)) " _
& "ORDER BY ItemName;"

This was done in ms access 2000. And I suppose that you have country in
one table and cities in another with a relation between them.

Hope this helps :-)

ja****@humlog.com skrev:
Hi,

I have a list box which displays countries names and a second listbox
which displays their cites (based on the selection made in ListBox 1)

If the user selects USA i want to display cities in the States - if the
user selects multiple countries I want to display the cities in ALL the
selected counties e.g. a user select US and England, the second list
would display ally cities in England and all the cities in the US.

I am new to javascript so would appreciate any help.
Jul 3 '06 #2
Hi,
Thanks for your help but I was really looking for a javascript
solution. I have been able to solve this using a postback to the
server.

Can anyone help??

Krij wrote:
Hi!

I solved a similar situation like this: When user picks an item in
lstCategory, lstItemDetail will be populated by:

With Me!lstItemDetail
.RowSource = ""
.ColumnCount = 4
.ColumnWidths = "0cm;7cm;2cm;0cm"
.BoundColumn = 1
.RowSource = "SELECT ItemID,ItemName,ItemPrice,CategoryID " _
& "FROM tblItems " _
& "WHERE (((CategoryID) = Forms!frmItems!lstCategory)) " _
& "ORDER BY ItemName;"

This was done in ms access 2000. And I suppose that you have country in
one table and cities in another with a relation between them.

Hope this helps :-)

ja****@humlog.com skrev:
Hi,

I have a list box which displays countries names and a second listbox
which displays their cites (based on the selection made in ListBox 1)

If the user selects USA i want to display cities in the States - if the
user selects multiple countries I want to display the cities in ALL the
selected counties e.g. a user select US and England, the second list
would display ally cities in England and all the cities in the US.

I am new to javascript so would appreciate any help.
Jul 3 '06 #3
JRS: In article <11**********************@j8g2000cwa.googlegroups. com>,
dated Sun, 2 Jul 2006 23:43:26 remote, seen in
news:comp.lang.javascript, ja****@humlog.com posted :
>I have a list box which displays countries names and a second listbox
which displays their cites (based on the selection made in ListBox 1)

If the user selects USA i want to display cities in the States - if the
user selects multiple countries I want to display the cities in ALL the
selected counties e.g. a user select US and England, the second list
would display ally cities in England and all the cities in the US.
Do you consider it reasonable to impose on unsuspecting users, who on
the WWW will not necessarily be using broadband landline, the burden of
downloading the names of all the cities in the world?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 3 '06 #4
It's totally irrelevant on what the values represent! I take it you
don't know the answer? I was actually using the country/city scenario
as an example because it made the question clear.

Dr John Stockton wrote:
JRS: In article <11**********************@j8g2000cwa.googlegroups. com>,
dated Sun, 2 Jul 2006 23:43:26 remote, seen in
news:comp.lang.javascript, ja****@humlog.com posted :
I have a list box which displays countries names and a second listbox
which displays their cites (based on the selection made in ListBox 1)

If the user selects USA i want to display cities in the States - if the
user selects multiple countries I want to display the cities in ALL the
selected counties e.g. a user select US and England, the second list
would display ally cities in England and all the cities in the US.

Do you consider it reasonable to impose on unsuspecting users, who on
the WWW will not necessarily be using broadband landline, the burden of
downloading the names of all the cities in the world?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 4 '06 #5

ja****@humlog.com skrev:
It's totally irrelevant on what the values represent! I take it you
don't know the answer? I was actually using the country/city scenario
as an example because it made the question clear.

Dr John Stockton wrote:
JRS: In article <11**********************@j8g2000cwa.googlegroups. com>,
dated Sun, 2 Jul 2006 23:43:26 remote, seen in
news:comp.lang.javascript, ja****@humlog.com posted :
>I have a list box which displays countries names and a second listbox
>which displays their cites (based on the selection made in ListBox 1)
>
>If the user selects USA i want to display cities in the States - if the
>user selects multiple countries I want to display the cities in ALL the
>selected counties e.g. a user select US and England, the second list
>would display ally cities in England and all the cities in the US.
Do you consider it reasonable to impose on unsuspecting users, who on
the WWW will not necessarily be using broadband landline, the burden of
downloading the names of all the cities in the world?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sorry....I was in the wrong group and my brain stopped functioning for
a second or two...

:-)

Jul 4 '06 #6


This is an old example I made:
------------------------
<html>
<head<title>none </title>
<script type="text/javascript">
var seafood=['shrimp','guppi','lobster','catfish'];
var foodtype=['italian','thai','chinese'];
var hardware=['pci peripherals','agps','cases','keyboards','mice','ne twork cables'];
function getList(el,el2) {

itemChosen=window[el.options[el.selectedIndex].value];
if (el.selectedIndex==0) return; // 1st option in 1stlist is the header
el2.length=0; // to reset the 2nd select

for (i=0;i<itemChosen.length;i++) {
newOpt=new Option(itemChosen[i],'this is '+itemChosen[i]); // 1st argument is
the text to show, 2nd is the value for it if any
el2.options[el2.length]=newOpt; // adds it
}

}

</script>

</head>
<body style="margin: 4em">

<form>

<select name="upperList" onchange="getList(this,this.form.belowList)">
<option value="">--- choose below ---</option>
<option value="seafood">want seafood </option>
<option value="foodtype">what food type </option>
<option value="hardware">hardware </option>
</select>

<select name="belowList" onchange="alert(this.options[this.selectedIndex].value)">
<option value="" </option>
</select>

<textarea onkeydown="(this.value.length>=200) ? return true : return false" name="s1"
cols="48" rows="4" ></textarea>
</form>
</body>
</html>

--------------------

bear in mind that I use arrays for the variables to be used to populate the Select "belowList",
now, for UK/US cities populating, that will be a huge array :), and you most likely will break
it down to counties/provinces/locales and such, so, the same applies, using an array, BUT do
asynchronous calls to the server upon the user selecting anything, so the list of the items to
be used, AND inserted as the arrays content, are fetched from the server only on a
user-selection basis, that way you don't preload everything and bogdown the page loading. To
make asynchronous calls check some premade sets on so-called Ajax.

Danny
Jul 4 '06 #7
ja****@humlog.com wrote:
Thanks for your help but I was really looking for a javascript
solution.
http://www.javascripttoolbox.com/lib/dynamicoptionlist/

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jul 4 '06 #8
Thanks guys, exactly what i was looking for.

Matt Kruse wrote:
ja****@humlog.com wrote:
Thanks for your help but I was really looking for a javascript
solution.

http://www.javascripttoolbox.com/lib/dynamicoptionlist/

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jul 9 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lamine Darbouche | last post by:
Can anybody help? I need to have three list boxes automatically populating each other, (ie when region is selected from the first listbox, it will populate automatically the second one which is...
0
by: Bill Brinkworth | last post by:
I want the user to type in part of a word, and I want to return all words from an Access word table that contains specified letters. If they were to type "fe??", it should return all words in the...
2
by: collie | last post by:
Hi, I have 2 listboxes. The first gets populated from the db as soon as the page loads. The second listbox get populated based on the user's selection from the first listbox. However,...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
6
by: P K | last post by:
I have a listbox which I am populating on the client (it contains a list of dates selected from calender). The listbox is a server control. When I get to the server after postback by selecting an...
4
by: c_shah | last post by:
I am a beginner and learning VB.net There are two wasy to bind a combobox or a listbox First approach is to assign a datasource and displaymember Second approach is to iterate through datarow...
15
by: NasirMunir | last post by:
I am trying to populate a listbox from another listbox on a access form. My first listbox has names of tables on a linked odbc databse. I am trying to display the tuples of the table in the second...
2
by: NvrBst | last post by:
I populate a ListBox with a LogFile that has about (~1000 lines). The ListBox's datasource is a BindingList<string>. Whenever I add the elements, with the datasource set, it takes about 2 mins. ...
11
by: angelicdevil | last post by:
ok this is wat i was trying to do...i have a list field with options A,B,P now i want the second list field to show data list by getting them from database based on the selection made in listbox1. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.