Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7490547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:40:26+00:00 2026-05-29T15:40:26+00:00

I have a web form with two drop-down boxes, and I’m looking for a

  • 0

I have a web form with two drop-down boxes, and I’m looking for a way to dynamically update the options of the second box based on selections from the first.

The first box represents a data type, and the second box is a list of databases associated with the selected type.

I have the basic code running smoothly here:

var TypeA_DbSuffixList = ['Test1', 'Test2', 'Test3'];
var TypeB_DbSuffixList = ['TestA', 'TestB', 'TestC'];

function fill_dbSuffixList(){

   document.getElementById("dbSuffixList").options.length = 0;
   var suffixMenu = document.getElementById("dbSuffixList");
   var dataFormat = document.getElementById("dataFormatType");
   var suffixList = dataFormat.value + "dbSuffixList";

   if (suffixList == 'TypeA_dbSuffixList') {
      for(index in TypeA_dbSuffixList) {
        suffixMenu.options[suffixMenu.options.length] = new Option(TypeA_dbSuffixList[index], index);
      }
   }

   if (suffixList == 'TypeB_dbSuffixList') {
      for(index in TypeB_dbSuffixList) {
        suffixMenu.options[suffixMenu.options.length] = new Option(TypeB_dbSuffixList[index], index);
      }
   } 
}

That code (activated whenever a selection is made in the dataType box) clears the existing list of options and repopulates the list based on the selected value of the “dataFormatType” box.

The problem that I face is that the actual lists of database tables are not hard coded and are instead generated with the following calls to the server to avoid repetitive editing of the page every time a new database is added:

var TypeA_dbSuffixList = ${TypeA_dbSuffixList};
var TypeB_dbSuffixList = ${TypeB_dbSuffixList};

These calls return the following code:

var TypeA_dbSuffixList = [Test1, Test2, Test3];
var TypeB_dbSuffixList = [TestA, TestB, TestC];

With the above code, the initial function treats each entry in the type arrays as an undefined variable, and nothing is ever written to the drop-down list.

If I were to add

var Test1 = "Apple";
var Test2 = "Orange";
var Test3 = "Grape";

prior to the “for” loop for TypeA, then selecting TypeA from the dataType drop-down list returns “Apple”, “Orange”, and “Grape” as the available databases for TypeA.

Visually, I see what needs to be changed. The [Test1, Test2, Test3] returns need to be [‘Test1’, ‘Test2’, ‘Test3’]. I’m just unsure exactly how to go about changing it, and have exhausted every web search I can think of.

Is there a way to either change the format of the returned arrays, or use the existing format and pass variable names as drop-down selections instead of using variable values?

Any help is greatly appreciated. I will continue to search for an answer on my own as well and will post it here should I find one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:40:28+00:00Added an answer on May 29, 2026 at 3:40 pm

    I think the cleanest solution would be to change the code on the server-side to generate a proper JavaScript array of Strings, with the values enclosed in single or double quotes.

    If that’s not possible for some reason, and you want a pure-JavaScript solution, then I suggest you wrap the entire JSP/ASP/PHP variable (not sure what framework you’re using) in double quotes, strip the string of brackets and spaces using a regex, and then split it into a string array using the comma as a delimiter.

    So in your JavaScript, this:

    var TypeA_dbSuffixList = ${TypeA_dbSuffixList};
    

    would become this:

    var TypeA_dbSuffixList = "${TypeA_dbSuffixList}".replace(/[\[\]\s]/g,"").split(",");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web form that I am attempting to implement dynamic drop down
I have two strange problems when I use routing in a web form application.
I have two AJAX UpdatePanels on my ASP.NET 2.0 web form. When I clic
I have two web form. example: a.aspx and b.aspx In a.aspx i have a
I have JSF page has two drop down lists and I want to load
I have two buttons on my web form. When clicking on the first button,
I am running a thread in C#. I have web form. I declared public
I have a web form that binds a DataGrid to a, normally, different data
I have a web form that has multiple ListBoxes, TextBoxes, DropDowns. If I put
I have a web form where I have a textbox in which the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.