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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:16:04+00:00 2026-05-16T14:16:04+00:00

The pasted below code i am using to create dropdown list and java script

  • 0

The pasted below code i am using to create dropdown list and java script for doing some stuffs

<td>
  <select id="currentCustomer" onchange="showSelectedCustomer(this)">
  <c:forEach var="Customer" items="${listCustomer}" >
      <option value="<c:out value="${Customer}" />"><c:out value="${Customer}" />
      </option>
 </c:forEach>
  </select>
</td>

function showSelectedCustomer(dropdown) {
var selectedCustomer = dropdown.options[dropdown.selectedIndex].value;
var currentCustomer = document.getElementById('currentCustomer');

 var context = document.forms[0].context.value;
document.forms[0].mode.value = "UPDATE";
document.forms[0].custName.value = dropdown.options[dropdown.selectedIndex].value;
document.forms[0].action=context+"/updateReportDetail.do";
document.forms[0].method="POST";
document.forms[0].submit();
}

My problem is
how to set the onselected value dynamically in drop down list.

Let me explain briefly here,

Initially at the time of logging application the landing “x.JSP” page will display drop down list with multiple customer names with first customer name as selected one by default.
If i select other customer name in drop down list i am calling Javascript[onchage event] to submitting to form and to do some other stuffs in DAO java class for the selected customer and returning back to “x.JSP” page.

Now the thing is i need to set the latest customer name [ie..the customer i processed in DAO java class] as onselected one in the drop down list.

Help me guys.Thanks for your effort in advance.

  • 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-16T14:16:05+00:00Added an answer on May 16, 2026 at 2:16 pm

    In your forEach loop, check if the Customer in your current iteration is the one that matches your predetermined choice. You don’t give any indication of how you’re choosing the “right” customer to be selected when the page loads, so I’ll use some pseudo-code for that.

    <c:forEach var="Customer" items="${listCustomer}" >
       <%  String selected = "";  
           if (customer.equals(predeterminedCustomerToBeSelected)) {
               selected = "selected"; }
       %>
          <option value="<c:out value="${Customer}" />" <%=selected%>><c:out value="${Customer}" />
          </option>
     </c:forEach>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting some very jerky scrolling while using the code below to create a
Initially, this code was written to create pretty urls. When using the code below,
The code pasted below was taken from Javadocs on HttpURLConnection . I get the
The code pasted below gets an exception on the line that says... InputStream in
The code pasted below is a simple JSF program, with an idea of having
I have a plot (sample code pasted below) that I am trying to add
Firstly sorry for the long piece of code pasted below. This is my first
The code I've pasted below works fine for drawing a line step by step
The complete code is copied and pasted below. I am new to javascript and
I am using the class pasted below to listen for the keypress event ctrl

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.