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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:53:12+00:00 2026-05-15T14:53:12+00:00

I have dropdown lists in two forms in a single .jsp. I would like

  • 0

I have dropdown lists in two forms in a single .jsp. I would like the change of any of the lists to trigger a post back to the .jsp itself with the currently selected parameters in both forms. But I couldn’t get it work. Here is the relevant part of the code:

Both forms are in the SearchBrowse.jsp. This is form1 (form2 will have an identical structure. Note that, I tried to use the same form id and hope to achieve this effect but didn’t work):

<c:set var="counter1" value="0"></c:set>
<c:set var="curSp" value="0"></c:set>

<form id="myForm" method="post" action="SearchBrowse.jsp">
    <b>Select Species:</b>&nbsp; 
    <select name="spChoice" size="1" onchange="submit()">
        <c:forEach var="sp" items="${species}">
            <c:choose>
                <c:when test="${param.spChoice == sp.name}">
                    <c:set var="spFlag" value=" selected"></c:set>
                    <c:set var="curSp" value="${counter1}"></c:set>
                </c:when>
                <c:otherwise>
                    <c:set var="spFlag" value=""></c:set>
                </c:otherwise>
            </c:choose>
            <option value="<c:out value='${sp.name}' />" <c:out value='${spFlag}' />>
                <c:out value="${sp.name}"></c:out>
            </option>
            <c:set var="counter1" value="${counter1 +1}"></c:set>
        </c:forEach>
    </select>
    <br></br>
</form> 

This is form2:

<c:set var="counter2" value="0"></c:set>
<c:set var="curChrm" value="0"></c:set>

<%-- Implement a dropdown list and and determine which javabean list to be displayed in the table --%>
<form id="myForm" method="post" action="SearchBrowse.jsp">
    <b>Select Chromosome to browse summary:</b>&nbsp; 
    <select name="chrmChoice" size="1" onchange="submit()">
        <c:forEach var="chrms" items="${riceChrmLocation}">
            <c:choose>
                <c:when test="${param.chrmChoice == chrms.name}">
                    <c:set var="selectFlag" value=" selected"></c:set>
                    <c:set var="curChrm" value="${counter2}"></c:set>
                </c:when>
                <c:otherwise>
                    <c:set var="selectFlag" value=""></c:set>
                </c:otherwise>
            </c:choose>
            <option value="<c:out value='${chrms.name}' />" <c:out value='${selectFlag}' />>
                <c:out value="${chrms.name}"></c:out>
            </option>
            <c:set var="counter2" value="${counter2 +1}"></c:set>
        </c:forEach>
    </select>
    <br></br>
</form> 

Currently when one form changed, the selection parameter of the other dropdown list is not posted back. I am not sure if it is the problem with scope. I tried various ways but couldn’t get it right. Did I do something wrong here? Also is this code a bit messy? (If it is, do u have any better suggestion on coding it in a neat way?) Thanks a lot.

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

    When you submit a form, only the fields from that form are sent on the request.

    You can either have just one form (with all your fields) or use JavaScript before submit to copy values from one form to hidden elements in the other.

    EDIT: here is a little JS example:

    <!-- test.html -->
    <html>
      <head>
        <script type="text/javascript">
          function doCopyAndThenSubmit() {
            var sourceInput = document.getElementById("source");
            //destination should be the hidden field, made it text to have a visual on the operation
            var destinationInput = document.getElementById("destination");
            destinationInput.value = sourceInput.value;
    
           //watch the address bar after the OK
           alert("Did the copy, press OK for the submit");
           document.forms["yourForm"].submit();
          }
        </script>
      </head>
      <body>
        Add some text in source and change the value in the select<br/>
        <form action="test.html" method="GET" name="yourForm">
          <select onchange="doCopyAndThenSubmit()">
            <option value="x">some value</option>
            <option value="y">some other</option>
          </select>
    
          <br/>Source:
          <!-- id must be unique in the entire document (don't confound with name) -->
          <input name="src" id="source" type="text" value="" />
    
          <br/>Destination:
          <input name="dest" id="destination" type="text" value="" />
        </form>  
      </body>
    </html>
    

    Usually you will have the name and id attributes with the same value for easy tracking (instead of referring to an input once by id and then by name); I used different values to reinforce the difference. And off course you will have the source in one form and the destination in another.

    <form name="form1" ...>
      ...
      <input name="source" id="source" type="text" value="" />
    </form>
    
    <form name="form2" ...>
      ...
      <input name="destination" id="destination" type="hidden" value="" />
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two dropdown lists (one dynamically populated, the other not) that determine the
I have two dropdown lists: <asp:DropDownList ID=Field_Type runat=server /> <asp:DropDownList ID=Field_SubType runat=server /> Field_Type
I have two DropDown lists which are already populated from the database. If you
Form contains two dropdown lists created using code below. Both dropdown list elements have
I have a form where there are two dropdown lists that are populated from
i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
I am using Asp.net dropdownlist in one of my form ..I have two dropdown
I have created a populated dropdown list in HTML. When the two dropdowns have
I have a user control in a master page with two drop down lists.
My question has two parts: Does anyone have any tips or references to some

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.