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 8698477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:44:27+00:00 2026-06-13T01:44:27+00:00

I have a gsp page and on that have a ‘ <g:select> ‘ element

  • 0

I have a gsp page and on that have a ‘<g:select>‘ element as:

<label class="control-label">Applicable Offices:</label>
<span class="span6">
    <select name="data.OfficeId" class="required j-office-select" style="height:26px;padding:1px;">
        <option value="0">Select an office...</option>
    </select>
</span>

I have to add more “option” dynamically for this select using JavaScript. My JavaScript part looks like:

$.ajax({
    url: epcm.urlManager.getUrl({controller: 'controllerName', action:'methodName'}),
    cache: false,
    contentType: "application/json",
    type: "POST",
    dataType: "json",
    data: JSON.stringify(params),
    success: function(officeData) {
        var selectOffice = dialog.find('.j-office-select');
        selectOffice.empty();
        // OfficeData is a list . For each officeData , I need to add an option to the’ select’, but ways I tried did not work.I need to know the proper use of $.each and how can I use that in this context
        selectOffice.append('<option value="'+officeData.id+'">'+officeData.regionName+'</option>' );
        selectOffice.removeAttr('disabled');
        window.location.reload();
    }
});

“OfficeData”, in the “success”, is a list. For each officeData, I need to add an option to the ’select’ described above, but the ways I tried did not work. I need help with the proper use of $.each and how can I use that in this context. Can anyone help? The above example is adding only the first one, missing all others.

  • 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-13T01:44:27+00:00Added an answer on June 13, 2026 at 1:44 am

    Should be something like this:

    $.each(officeData, function(index, item){
       selectOffice.append('<option value="'+item.id+'">'+item.regionName+'</option>' );
    } );
    

    However, in your example it does not seem like officeData is a collection since officeData.id and officeData.regionName are not nested inside items. You could use console.log(officeData); to output the data structure to your browser console (assuming you are using something like Chrome or FireFox+devtools).

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

Sidebar

Related Questions

I have a page/gsp that displays 3 different classes. This means that I need
I have the following code in my gsp <select onChange=${remoteFunction(action:'superior', controller:'employee', params: '\'name=\' +
I have a .gsp, that displays a number in the page. The problem is,
In my GSP page, I have this form: <g:form action=ajaxAdd> <g:textArea id='postContent' name=content rows=3
I have a gsp page with a form that I would like to put
I have the folowing gsp page: <g:form controller=?? action=??> <h1>Search</h1> <g:submitButton name=search value=Search/> <div
My question is, I have a page say view.gsp and containing a form that
I have a very simple gsp page that has a button. I'm trying to
I have problem with encode slash in url. Problem: from request in GSP page:
I have a form submission that is rendering a gsp template and inserting it

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.