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

  • Home
  • SEARCH
  • 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 8139715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:55:22+00:00 2026-06-06T11:55:22+00:00

I am filling a drop down based on the value selected in the first

  • 0

I am filling a drop down based on the value selected in the first drop down.Data being sent back from server is in JSON format and using JQuery to parse and fill the second select tag

<select name="abc" id="jobName">
  <option value="-1">Please select a  Job</option>
 </select>

This is my Jquery code

var selectedGroup = document.getElementById(groupDropDownId);
var groupdata = selectedGroup.options[selectedGroup.selectedIndex].value;
var formInput='group='+groupdata;

$.getJSON('search/getSchedulerJobListForGroup',formInput,function(data) {

    $('.result').html('' + data.jobList + '');
    $.each(data.jobList,function(index, value){
    var jobId = document.getElementById(resetDropDownId);
    var option=new Option(value,value);
    try{
         jobId.add(option);
       }
        catch(e){
          jobId.appendChild(option);
         }
       });
      });

    $("#jobName")[0].selectedIndex = 1;
    // $("#jobName").val($("#triggerjobName option:first").val());

in above code groupDropDownId is ID of the drop down based on whose value, second drop down will be filled.resetDropDownId is ID of second drop down which i am trying to fill from JSON data getting from the server.

Upon filling the drop down, its also creating an empty option tag and it is getting select by default.
I am not sure if i can add some default value to that empty option so that i can select that default option value like “please select bla bla.”

also i tried to select first element from the drop down but nothing seems working for me.I am wondering what i am doing wrong here?

  • 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-06-06T11:55:23+00:00Added an answer on June 6, 2026 at 11:55 am

    Based on your question, it looks like you want to know how to change the value and text of an element within a dynamically populated select list.

    Currently, you have this statement $("#jobName")[0].selectedIndex = 1; sitting outside of your getJSON request. If you move this inside of the getJSON function, it will work as expected.

    If you want to set the value and text of that object, you’ll want to use ->

    $('#jobId option:first').val("Some Value").text("other stuff");
    

    You can see a working JS Fiddle using dynamically populated select list from a JSON object.

    Fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to automate the filling of a master excel file from selected rows
I'm developing java EE database application(JSF) where I fill drop down menus from database.
I'm filling in a Word template with data that's been collected from user input.
I'm filling a drop-down list using the following: var columnNames = db.Mapping.MappingSource.GetModel(typeof(StaffDirectoryDataContext)) .GetMetaType(typeof(Person)).DataMembers; I'm
I have dropdownlist,which get filled from table1.That table1 has Zero value.While filling the dropdown,want
I'am filling tables in .net DataSet with data. There is a nested relation between
My co-worker is filling a System::String object with double-byte characters from an unmanaged library
I'm filling an XML document manually using C# and I need to have <data>
I have problems filling a temporary table with the resultset from a procedure call
I am filling a GridView with the data table but on each row I

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.