0

I want to get the value of the bfnsCode select tag onchange to servlet without page refreshing. And also the value of taxtCode. How should I do that? Here's my code...

JSP:

<label style="font-size: 17px;">BIR-Form Number</label><br>         
    <select name="bfnsCode" id="bfnsCode" class="sel" style="width: 245px; margin-left: 0;">
        <option selected="selected" value=""></option>
        <c:forEach var="bircode" items="${birtypelist}">
        <option value="${bircode.bfnsCode}">${bircode.bfnsCode}</option>                             
        </c:forEach>
    </select>
    <br><br>

<label style="font-size: 17px;">Tax Type</label><br>            
    <select name="taxtCode" id="taxtCode" class="sel" style="width: 245px; margin-left: 0;">
        <option selected="selected" value=""></option>
        <c:forEach var="taxcode" items="${taxtypelist}">
        <option value="${taxcode.taxtCode}">${taxcode.taxtCode}</option>
        </c:forEach>                                                                                        
    </select>
    <br><br>

<label style="font-size: 17px;">Account Code</label><br>    
    <select name="taxtDesc" id="taxtDesc" class="sel" style="width: 245px; margin-left: 0;">
        <option selected="selected" value=""></option>
        <c:forEach var="taxdesc" items="${taxdesclist}">
        <option value="${taxdesc.taxtDesc}">${taxdesc.taxtDesc}</option>
        </c:forEach>                                                                                    
    </select>

servlet:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    TblBIRFormNoDAO birdao = DAOFactory.getDaoManager(TblBIRFormNo.class);
    List<TblBIRFormNo> birtypelist = birdao.getAllBirFormNumber();
    request.setAttribute("birtypelist", birtypelist);

    String bir = request.getParameter("bfnsCode");
    TblTaxTypeDAO taxdao = DAOFactory.getDaoManager(TblTaxType.class);
    if(bir != null){
        Debugger.print("BFNSCODE : "+bir);
        List<TblTaxType> taxtypelist =  null;
        taxtypelist = taxdao.findAlltaxtCode(bir);
        request.setAttribute("taxtypelist", taxtypelist);
    }

    String tax = request.getParameter("taxtCode");
    TblTaxTypeDAO tdao = DAOFactory.getDaoManager(TblTaxType.class);
    if(tax != null){
        Debugger.print("TAXCODE : "+tax);
        List<TblTaxType> taxdesclist = tdao.findAlltaxtDesc(bir, tax);
        request.setAttribute("taxdesclist", taxdesclist);
    }

    request.getRequestDispatcher("/servlet-test.jsp").forward(request, response);
}

From this code in servlet the request getParameter gives a null value. How to get the right value when user selected a value in drop down list?

P.S

2nd drop down is based on 1st and 3rd drop down is based on 2nd so the 2nd and 3rd drop down is empty as of the moment because I'm not getting the value of parameter bfnsCode(1st drop down). Please help me out, I badly need this.

Coder
  • 6,948
  • 13
  • 56
  • 86
RMsplace
  • 53
  • 9

1 Answers1

1

if you're new to ajax i would use jquery, it's very easy to do ajax with it. Ajax get petition . The documentation is very easy and understandable

jd.carretero
  • 139
  • 1
  • 1
  • 6