Dynamically changing the values in a drop down list in Visual Studio / Visual Web Developer

Posted on 2008-01-29
Medium Priority
Last Modified: 2013-11-27
I have two drop down boxes.

DDAccomm & DDPrice

DDAccomm is bound to my database and gets it's values from a table.

DDPrice is hard coded

I want DDAccomm to change the values of DDPrice according to what is selected

e.g. If then selection of DDaccomm is position 1 or 2 then leave, if it's position 3 or 4 then change the values.  These values are not to come from the DB.

Question by:nickrjsmith

Accepted Solution

Jezcentral earned 1500 total points
ID: 20779670
As you know what the values will be, you can store them in arrays, and use CSS to show/hide them as required:

<script type="text/javascript">
var odd = new Array("one", "three", "five");
var even = new Array("two", "four");

function hide(numberType) {
      for (var i=0; i<numberType.length; i++) {
            document.getElementById(numberType[i]).style.display = "none";
function show(numberType) {
      for (var i=0; i<numberType.length; i++) {
            document.getElementById(numberType[i]).style.display = "block";
<p>Show <a href="#" onclick="hide(even); show(odd); return false;">odd numbers</a>.</p>
<p>Show <a href="#" onclick="hide(odd); show(even); return false;">even numbers</a>.</p>
      <option id="one">1</option>
      <option id="two">2</option>
      <option id="three">3</option>
      <option id="four">4</option>
      <option id="five">5</option>


Author Comment

ID: 21059179
i used on selected index change although this solution would have worked too

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
Suggested Courses
Course of the Month7 days, 5 hours left to enroll

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question