473,394 Members | 1,752 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,394 software developers and data experts.

passing values of multiple select in javascript

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 1794
ronverdonk
4,258 Expert 4TB
Show your code. (and please do it within the appropriate code tags)

Ronald
Feb 27 '08 #2
hsriat
1,654 Expert 1GB
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="changeOption(this, 'Delhi')">India</option>
<option value="UK" onclick="changeOption(this, 'Wales')">UK</option>
<option value="USA" onclick="changeOption(this, 'Illinois')">USA</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 Expert 256MB
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 Expert 1GB
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 Expert 4TB
I will move this thread to the JavaScript forum.

moderator
Feb 27 '08 #6
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">India</option>
<option value="US">United States</option>
<option value="UK">United Kingdom</option>

</select>


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

<option value="NY">New York</option>
<option value="Wales">Wales</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 Expert 4TB
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 Expert Mod 8TB
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
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...
2
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"...
1
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...
1
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.