Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java
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 1:28am

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 at 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
0 OriginalGriff 400
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 264
3 BillWoodruff 245
4 CPallini 195
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 5 Aug 2011
Copyright © CodeProject, 1999-2014
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