Hi, I plan to use drop down lists to populate team results and will use the standard country/state drop down lists as the base code.
The question: how can I populate multiple (5) states from entering one country?
Here is the current code which works for one state...however if I add another "State" (class=td100) row identical to the one below neither state field offers the drop down list. -
<form name="form1" action="">
-
<table style="width:590px;"><tbody><tr>
-
<td style="width:100px;">Country</td>
-
<td><select name="cboCountry" style="width:auto;clear:none;" onchange="Fill_States();">
-
<option selected="selected">12345678901234567890</option>
-
<option>temp</option></select></td>
-
</tr>
-
-
<tr>
-
-
<td class="td100">State<br />Province</td>
-
<td title="Enable javascript to fill the lists."><select name="cboState" style="width:auto;" onchange="Update_Globals();">
-
-
<option selected="selected">12345678901234567890</option>
-
<option>temp</option></select></td></tr>
-
</tbody></table>
-
Many thanks
Barry
5 3941 gits 5,390
Recognized Expert Moderator Expert
as far as i understand that ... this is a JavaScript issue ... since you cannot achieve that just with html ... to help you with this, you should explain a bit more what you mean with 'standard country/state drop down lists' and how the code currently populates the one list that is filled correctly. may be posting some code regarding that would help a lot.
kind regards
Thanks. Here is a cut-down version of the code... - var postState = '';
-
var postCountry = '';
-
-
-
var state = '\
-
US:AK:Alaska|\
-
US:AL:Alabama|\
-
etc
-
etc
-
';
-
-
// Country data table
-
//
-
// To edit the list, just delete a line or add a line. Order is important.
-
// The order displayed here is the order it appears on the drop down.
-
//
-
var country = '\
-
AF:Afghanistan|\
-
AL:Albania|\
-
etc
-
etc
-
';
-
-
function TrimString(sInString) {
-
if ( sInString ) {
-
sInString = sInString.replace( /^\s+/g, "" );// strip leading
-
return sInString.replace( /\s+$/g, "" );// strip trailing
-
}
-
}
-
-
// Populates the country selected with the counties from the country list
-
function populateCountry(defaultCountry) {
-
if ( postCountry != '' ) {
-
defaultCountry = postCountry;
-
}
-
var countryLineArray = country.split('|'); // Split into lines
-
var selObj = document.getElementById('countrySelect');
-
selObj.options[0] = new Option('Select Country','');
-
selObj.selectedIndex = 0;
-
for (var loop = 0; loop < countryLineArray.length; loop++) {
-
lineArray = countryLineArray[loop].split(':');
-
countryCode = TrimString(lineArray[0]);
-
countryName = TrimString(lineArray[1]);
-
if ( countryCode != '' ) {
-
selObj.options[loop + 1] = new Option(countryName, countryCode);
-
}
-
if ( defaultCountry == countryCode ) {
-
selObj.selectedIndex = loop + 1;
-
}
-
}
-
}
-
-
function populateState() {
-
var selObj = document.getElementById('stateSelect');
-
var foundState = false;
-
// Empty options just in case new drop down is shorter
-
if ( selObj.type == 'select-one' ) {
-
for (var i = 0; i < selObj.options.length; i++) {
-
selObj.options[i] = null;
-
}
-
selObj.options.length=null;
-
selObj.options[0] = new Option('Select State','');
-
selObj.selectedIndex = 0;
-
}
-
// Populate the drop down with states from the selected country
-
var stateLineArray = state.split("|"); // Split into lines
-
var optionCntr = 1;
-
for (var loop = 0; loop < stateLineArray.length; loop++) {
-
lineArray = stateLineArray[loop].split(":");
-
countryCode = TrimString(lineArray[0]);
-
stateCode = TrimString(lineArray[1]);
-
stateName = TrimString(lineArray[2]);
-
if (document.getElementById('countrySelect').value == countryCode && countryCode != '' ) {
-
// If it's a input element, change it to a select
-
if ( selObj.type == 'text' ) {
-
parentObj = document.getElementById('stateSelect').parentNode;
-
parentObj.removeChild(selObj);
-
var inputSel = document.createElement("SELECT");
-
inputSel.setAttribute("name","state");
-
inputSel.setAttribute("id","stateSelect");
-
parentObj.appendChild(inputSel) ;
-
selObj = document.getElementById('stateSelect');
-
selObj.options[0] = new Option('Select State','');
-
selObj.selectedIndex = 0;
-
}
-
if ( stateCode != '' ) {
-
selObj.options[optionCntr] = new Option(stateName, stateCode);
-
}
-
// See if it's selected from a previous post
-
if ( stateCode == postState && countryCode == postCountry ) {
-
selObj.selectedIndex = optionCntr;
-
}
-
foundState = true;
-
optionCntr++
-
}
-
}
-
// If the country has no states, change the select to a text box
-
if ( ! foundState ) {
-
parentObj = document.getElementById('stateSelect').parentNode;
-
parentObj.removeChild(selObj);
-
// Create the Input Field
-
var inputEl = document.createElement("INPUT");
-
inputEl.setAttribute("id", "stateSelect");
-
inputEl.setAttribute("type", "text");
-
inputEl.setAttribute("name", "state");
-
inputEl.setAttribute("size", 20);
-
inputEl.setAttribute("value", postState);
-
parentObj.appendChild(inputEl) ;
-
}
-
}
-
-
function initCountry(country) {
-
populateCountry(country);
-
populateState();
-
}
-
//-->
-
</script>
-
-
-
-
// End -->
gits 5,390
Recognized Expert Moderator Expert
as you could see from your posted code ... you could only populate ONE list since you have hardcoded ids that are use like this: - document.getElementById('stateSelect');
so to poulate more then one node you could pass an additional id or id-list to the functions and use that, so you could either make a number of calls with one id or write a loop inside the function so that you could pass a list ...
kind regards
Thanks for your help on this. I'm fine with html/css, even php, but js is sadly beyond me at the moment. I found this free drop down coding and thought it would be ideal for snooker league teams to send in their results ie team name is selected and then player names are populated (as states are in the example).
If it's not too much trouble would you be able to give me the changes I would need to make to the code to populate 5 nodes from one drop down selection? Kind rgds
Barry
gits 5,390
Recognized Expert Moderator Expert
?? ... i will not give you the entire solution for this ... because this is not what i'm here for. in case you show some efforts to learn and try something for your own i'm glad to help you out ...and point you to the right direction, the idea for the adaptions is up there in my previous post ... :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: B. G. Mahesh |
last post by:
hi
In the registration form I have city, state, country fields. I was
wondering if there was a database available on the net which has the
list of states in each of the countries. That way when a user selects
a country I could automatically populate the state drop down menu
Any help is appreciated
-- bg mahesh
|
by: Kingdom |
last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off
- type B I have 12 off etc.
I'm using
Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM
Parts_Table")
to populate a drop down but would like to use several drop downs
restricting the contents of each drop down to the records pertaining to one
|
by: Aaron Prohaska |
last post by:
I'm having the problem with this drop down list on postback. For some
reason both the ListItems get selected when I change the selected item.
Using the code below I'm building the drop down list in the overriden
CreateChildControls method and setting the selected item. Then when I
change the item in the drop down list the list is rebuilt from
viewstate, but the initial item is still selected causing the error
below.
I also have a number...
|
by: somaskarthic |
last post by:
Hi
In my php page , there is a user registration form. Here the user has to select
the country, state, city from the drop down box. How this can be handled in php?
If a country is selected in a drop down box , its corresponding states should be
populated in the state drop down box. If a state is selected , its corresponding
cities should be populated in the city drop down box. Where all these data has to be stored and retrieved. What...
|
by: Jeff Gardner |
last post by:
Greetings:
I have a table with 3 pieces of data that I would like to use to
dynamically populate 3 drop downs using javascript. The fields are
state, orgname, office. If it's not already obvious, I'd like orgname
drop down to change when a state is selected and I would like office
drop down to change when an orgname is selected. I can do this with
multiple tables but am having difficulty getting it to work when the
data is in the...
| |
by: Mpho Pole |
last post by:
Hi everyone.I'm a newly minted member, and I'm glad to be here. Now that the pleasanteries are out of the way, my problem is as follows:
I have an SQL query which receives multiple parameters from a form depending on the users' choice. Most of the parameters are in drop down combos on the said form and I would like my SQL statement to return results according to the values of the drop downs regardless of the number of drop downs.
The drop...
|
by: jakas |
last post by:
Hi
In my php page , there is a user registration form. Here the user has to select
the country, state, city from the drop down box. How this can be handled in php?
If a country is selected in a drop down box , its corresponding states should be
populated in the state drop down box. If a state is selected , its corresponding
cities should be populated in the city drop down box. Where all these data has to be stored and retrieved. What type...
|
by: kishorealla |
last post by:
Hello
I need to create a web bot/crawler/spider that would go into different web sites and collect data for us and store in a database. The crawler needs to 'READ' the options on a website (either from drop-downs, radio-buttons or check-boxesand) to create some input itself OR use some generic pre-defined words (that we provide it with).
For example, a webpage might be structure with a text field and some drop-downs. Typically, if the user...
|
by: tokcy |
last post by:
Hi everyone,
I need the world database of country state and city. Actually i have three drop down option in my project in 1st drop down country name should come from database and 2nd drop down state name should come from database according to country and in 3rd drop down cities name should come from database according to states.
I have tried many search engine but i could not get any proper info regarding this i mean some time i get whole...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |
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...
| |