/    Sign up×
Community /Pin to ProfileBookmark

Dropdowns populate EACH OTHER

Hi there,

I have two dropdowns and I need them to populate one another.

First dropdown contains common names of species (ie. ratsnake, tree frog, ribbonsnake). When a user selects this, its scientific name would automatically appear in the second dropdown. There are bio nerds, though, that only know scientific names, so I would also need the capability of having the scientific name populate the common name dropdown. (ie. selecting Lithobates sylvaticus would make wood frog appear in common name).

Is this possible? Any help would be awesome.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERMar 19.2009 — This might solve half of your problem: ?
<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Dual Selections&lt;/title&gt;
&lt;script type="text/javascript"&gt;
// From: http://www.webdeveloper.com/forum/newreply.php?do=postreply&amp;t=204951

var a = ['|-- Reptile Examples --','|Ratsnake','|Tree frog','|Ribbonsnake']; // automatic value assignments
var b = ['|-- Mammal Examples --','123|Whale','456|Mouse','789|Man']; // demonstration of value assignments
var c = ['|-- Bird Examples --','|Sparrow','|Woodpecker'];

function choice(IDS,t){
s = document.getElementById(IDS);
for (var i = s.options.length; i &gt;= 0 ; i--) { s.options[i] = null; }
if (t != 0){
var z = [];
switch (t) {
case '1' : z = a; break;
case '2' : z = b; break;
case '3' : z = c; break;
default : alert('Invalid entry: '+IDS+' : '+t+'nn'+z); break;
}
var tmp = [];
for(i = 0; i &lt; z.length; i++ ) {
tmp = z[i].split('|')
if (tmp[0] == '') { tmp[0] = tmp[1]; } // puts something into value other than ''
s.options[i] = new Option(tmp[1],tmp[0],false,false);
}
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;SELECT id="Species" onChange="choice('CommonName',this.value)"&gt;
&lt;option value="0"&gt;-- Please Select --&lt;/option&gt;
&lt;option value="1"&gt;Reptile&lt;/option&gt;
&lt;option value="2"&gt;Mammal&lt;/option&gt;
&lt;option value="3"&gt;Bird&lt;/option&gt;
&lt;/SELECT&gt;

&lt;!-- onChange below only for testing purposes -- not needed --&gt;
&lt;SELECT id="CommonName" onChange="alert('Value: '+this.value)"&gt;&lt;/SELECT&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@Sterling_IsfineMar 19.2009 — You don't mean [I]populate[/I] you mean [I]select[/I], namely a pair of listboxes that each translate the other's selected option.

[CODE]<select id='commonName' onclick='document.getElementById("sciName").selectedIndex=this.selectedIndex'>
.
.
.
<select id='sciName' onclick='document.getElementById("commonName").selectedIndex=this.selectedIndex'>[/CODE]
Copy linkTweet thisAlerts:
@JMRKERMar 20.2009 — You don't mean [I]populate[/I] you mean [I]select[/I], namely a pair of listboxes that each translate the other's selected option.
[/QUOTE]

I guess we'll just have to wait to see what 'amphibboy' intent is. ?

?
×

Success!

Help @amphibboy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...