By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,780 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,780 IT Pros & Developers. It's quick & easy.

Populating Second Listbox

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a


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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.