Click here to Skip to main content
13,043,898 members (47,887 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi,

Please any one help below requirements. It would be very useful for me . Advance Thanks

"change dropdownlist selected index with javascript"

for example I have two dropdown list in form , If I click values in first dropdown list. automaticaly respective values to show the scecond in drop down list .

A- dropdown list B- drop down list

1 4
2 5
3 6


for example If I click values "3" in first dropdown list. automaticaly respective values to show "6" the scecond in drop down list

This For your Reference

A-drop downlist B-drop downlist
3 6
Posted 5-Aug-11 0:28am
Updated 31-May-16 3:27am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Match the text value with the value you are given. If it is matched with the text of the option you can set the selectedIndex to that.

var dropdownlistbox = document.getElementById("DropdownID")
 
for(var x=0;x < dropdownlistbox.length -1 ; x++)
{
   if(givenValue == dropdownlistbox.options[x].text)
 
      dropdownlistbox.selectedIndex = x;
}
 


if you know the index then directly you can give like this
document.getElementById("DropDownID").selectedIndex = x;
  Permalink  
v2
Comments
RaviRanjankr 5-Aug-11 14:01pm
   
My 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 31 May 2016
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100