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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:33:18+00:00 2026-05-27T21:33:18+00:00

I have a jsp with two drop down location and department. The value of

  • 0

I have a jsp with two drop down location and department.

The value of department dropdown is populated based on the value of location through Ajax.

But when I try to save the page I can’t access the value of department dropdown if the first item from the department drop down is selected.

But if 2nd or 3rd item is selected it can be accessed from the servlet.

<form id="form1" name="crtdocfrm" action="CreateLocation" method="post">
  <fieldset width="50%">
    <legend>Division</legend>
    <table id="table1">
      <tr class="tr_stylebutton">
        <td>Location Name</td>
        <td><select name="locName" onChange="showDept(this.value)">
          <option value="-1">--select--</option>
          <%
            Iterator itrLocation = arlLocation.iterator();
            while (itrLocation.hasNext()) {
          %>
          <option value=<%=itrLocation.next()%>><%=itrLocation.next()%>
          </option>
          <%}%>
        </select></td>
      </tr>

      <tr class="tr_stylebutton">
        <td>Department Name</td>
        <td>
          <select name="ddDeptName" onChange="alert(this.value)"></select>
        </td>

      </tr>
      <tr class="tr_stylebutton">
        <td>Division ID</td>
        <%
          LocationPolulate lp = new LocationPolulate();
          int Div_Id = lp.DivisionId();
        %>
        <td><input type="text" name="divID" disabled="true" value=<%=Div_Id + 1%>/></td>
      </tr>

      <tr class="tr_stylebutton">
        <td>Division Name</td>
        <td><input type="text" name="divName" value=""/></td>
      </tr>
    </table>

    <table border="0" width="55%" align="left" id="table-button">
      <tr class="tr_stylebutton">
        <td align="right"><input type="submit" value="Save" class="button"/></td>
        <td align="left"><input type="submit" value="Cancel" class="button"/></td>
      </tr>
    </table>
  </fieldset>
  &nbsp;&nbsp;<br/>
</form>

Servlet

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);

    int intLocId = Integer.parseInt(request.getParameter("locName"));
    String strDivNm = (String) request.getParameter("divName");
    int intDeptId = Integer.parseInt(request.getParameter("ddDeptName"));

    LocationPolulate lp = new LocationPolulate();
    int Res = lp.InsertDivision(strDivNm, intLocId, intDeptId);

    if (Res == 0) {
        request.setAttribute("Errmsg", "Error Cannot Save Division");
        RequestDispatcher dis1 = getServletContext().getRequestDispatcher("/AddDivision");
        dis1.forward(request, response);
    } else {
        int Div = lp.DivisionId();
        request.setAttribute("succmsg", "Successfully saved Division with division id:" + Div);
        RequestDispatcher dis1 = getServletContext().getRequestDispatcher("AddDivision.jsp");
        dis1.forward(request, response);
    }
}

Any ideas?

  • 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-27T21:33:19+00:00Added an answer on May 27, 2026 at 9:33 pm

    sorry for adding code as a part off comment…i could not fit the whole code so i had to add the comment..there was a mistake in the java script.the correct one is given below.Thanks all for your suggestion …

    function stateChanged()
    {
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
            var showdata = xmlHttp.responseText;
            var strar = showdata.split(":");
    
            if(strar.length==1)
            {
                document.getElementById("locName").focus();
                alert("Please Select location Id");
            }
            else if(strar.length>1)
            {
                option=new Option("---Select---", -1);
    
                document.crtdocfrm.ddDeptName.options[0]=option;
                for(var i=1;i<strar.length-1;i=i+2)
                {
                    option=new Option(strar[i+1], strar[i]);
                    document.crtdocfrm.ddDeptName.options[(i-1)/2+1]=option;
                }
            }
        }
    }
    

    i am getting the id and name in the same string from another jsp and spliting it to get the value of the different department id and name.

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

Sidebar

Related Questions

Say I have two drop downs which are populated when the my jsp loads
I have dropdown lists in two forms in a single .jsp. I would like
I have a drop down list with two values (for now..) with other elements
I have a jsp page where I'm trying to send multiple (two currently) ajax
I have a jsp page with two radio tags. The page contains a struts2
I have two list on my request on jsp. First one is productGroupName, and
I have a jsp page which should load a popup using ajax. The content
Can I refresh a HTML component in JSP? I have two dropdowns. On selection
I have two jsp(one is main page, another one is new window) and single
I have written two JSP pages: outerPage.jsp and innerPage.jsp . The outerPage.jsp includes innerPage.jsp

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.