473,839 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing values of multiple select in javascript

2 New Member
Hi,

I ll illustrate my problem with an example.

I have a multiple select option for choosing countries of the world.Suppose the options available are

India
America
UK

The states in another multiple select field

Delhi
Chicago
Wales

When i choose India and America from the Countries multiple select, Only the Options Delhi and chicago must be available in the states. I looked for solutions but could not get an optimum solution.

Its pretty urgent.Please Guide me on how to do this.

Thanks in Advance

Ramya
Feb 27 '08 #1
8 1811
ronverdonk
4,258 Recognized Expert Specialist
Show your code. (and please do it within the appropriate code tags)

Ronald
Feb 27 '08 #2
hsriat
1,654 Recognized Expert Top Contributor
I would like to suggest you to hide (style="display: none;") the select box with states in the beginning. When any of the country is selected, display the states' select box with the corresponding options.

[html]<select name="country[]" id="country" multiple>
<option value="India" onclick="change Option(this, 'Delhi')">India </option>
<option value="UK" onclick="change Option(this, 'Wales')">UK</option>
<option value="USA" onclick="change Option(this, 'Illinois')">US A</option>
</select>
<select name="state[]" id="state" style="display: none;"></select>[/html]
Expand|Select|Wrap|Line Numbers
  1. function changeOption (which, state) {
  2.     if (which.selected) addOption(state);
  3.     else remOption(state);
  4.     document.getElementById('state').style.display = document.getElementById('country').value ? '' : 'none';
  5. }
  6.  
And for addOption() and remOption(), see this tutorial

I think this would solve your problem.
Feb 27 '08 #3
harshmaul
490 Recognized Expert Contributor
This is php, and it can be done with php, but if you want a javascript solution, your going to have to ask the guru's in that forum.

If you want to use PHP, you will need to use a post back, either by making the form post back when u select one of the countries, or having a button that does the posting back. either way please post code as ronald said.
Feb 27 '08 #4
hsriat
1,654 Recognized Expert Top Contributor
This is php, and it can be done with php, but if you want a javascript solution, your going to have to ask the guru's in that forum.

If you want to use PHP, you will need to use a post back, either by making the form post back when u select one of the countries, or having a button that does the posting back. either way please post code as ronald said.
He actually asked for JavaScript, and posted it in PHP forum.
Feb 27 '08 #5
ronverdonk
4,258 Recognized Expert Specialist
I will move this thread to the JavaScript forum.

moderator
Feb 27 '08 #6
ramyaraghavan
2 New Member
Show your code. (and please do it within the appropriate code tags)

Ronald
I have a code like this
[HTML]<select name="Country[ ]" class="textnone " multiple >
<option value="0"> - - Select - - </option>
<option value="India">I ndia</option>
<option value="US">Unit ed States</option>
<option value="UK">Unit ed Kingdom</option>

</select>


<select name="places[ ]" class="textnone " multiple>
<option value="0"> - - Select - - </option>
<option value="Delhi">D elhi</option>
<option value="TN">Tami l Nadu</option>
<option value="Chicago" >Chicago</option>

<option value="NY">New York</option>
<option value="Wales">W ales</option>

</select>
[/HTML]
Here Delhi, Tamil Nadu are places in the Country India
Chicago, New York are places in the country United States
Wales is a place in United Kingdom

When I select India and United States only options Delhi, Tamil Nadu, Chicago and New York should be available within palces[ ] for the Client to choose.

Please Guide me on how to do this.


Thanks in advance
Mar 3 '08 #7
ronverdonk
4,258 Recognized Expert Specialist
To start with: why don't you show some courtesy to the members of this forum who are willing to help you, and show the code within the appropriate code tags, as requested in a previous post.

Ronald
Mar 3 '08 #8
acoder
16,027 Recognized Expert Moderator MVP
ramyaraghavan, please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future. Thanks!
Mar 3 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

12
6566
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
2
2929
by: Peter | last post by:
Hello I have the following tag <select name="cat" id="cat" onchange="popUpWin('cmPhaseReload.php?category='+document.getElementById('cat').options.value ,600,600,'yes')" class="tbl_result" size="1"> the cat field is a drop down list
1
2397
by: DigitalPrankster | last post by:
I have a form that I am using to generate an email with several user selected fields being part of it. As part of this form, I have a select box which allows the user to select which email addresses it should be sent to. The box works great except that the CGI script I'm sending the values to can only parse a single line for each field in the form. The issue comes into play when someone selects more than one value in the select box, the...
1
2182
by: mbcode | last post by:
I am trying to use a Javascript picklist box and then echo the chosen values back to the screen (and insert in the db later) but I am getting the Button value rather than the list values. I have followed the advice on the forum to us and ID and getElementByID in the <select> line, but no luck. Thanks in advance HTML </head> <body> <form method="post" name="combo_box" action=subscribe3.php> <table cellpadding="4" cellspacing="0"...
0
9855
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10908
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10295
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7829
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7018
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4487
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.