Results 1 to 4 of 4

Thread: Problem facing to keep Dropdown selected

  1. #1

    Default Problem facing to keep Dropdown selected

    HI All,
    I have one entry JSP page.
    There I have one combo box, containing the empIDs.
    On selecting one value from that combo box, all the other text box need to be populated by the values from the database according to the empID selected from the combo box.

    Now I am able to populate all the text boxes.
    But the first combobox(empID) needs to be stay selected (the value which one is selected initially) after the text boxes being populated.
    I am unable to do it.

    Following is the code from JSP page:
    Code:
    <spring:bind path="Data24by7.empNo">
    				<TD align="left">
    				<select name="empNo" onChange="frm_submit()">
    					<option value ="0">Select EmpID</option>
    
    				<c:forEach var="data24by7" items="${Model.empids}">
    						<option value ="<c:out value="${data24by7.empNo}"/>"><c:out value="${data24by7.empNo}"/></option>
    				</c:forEach>
    				</select>
    					<!--<input type="text" name="empNo" maxlength=10 >-->
    				</TD>
    				</spring:bind>
    After populating all the text boxes, the combo box shows "Select EmpID".

    Now what should I do to make it selected.

    Please help me...
    It will be a great help for me.
    Regards,
    Sasikanth

  2. #2
    Join Date
    Aug 2004
    Location
    San Francisco, CA
    Posts
    66

    Default

    Are you hitting the server to get the data from the database? That is, are you refreshing the page? I assue you are because of the frm_submit() JS call.

    If you are, then you need to put some code in the page that will mark the currently selected empid with "selected" (or selected="selected" for valid xhtml).

    An example might look like:

    Code:
    <spring:bind path="Data24by7.empNo">
      <select name="empNo" onChange="frm_submit()">
        <option value ="0">Select EmpID</option>
        <c:forEach var="data24by7" items="${Model.empids}">
          <option value ="<c:out value="${data24by7.empNo}"/>"
            <c:if test="${status.value == data24by7.empNo}">selected="selected"</c:if>>
            <c:out value="${data24by7.empNo}"/>
          </option>
        </c:forEach>
      </select>
    </spring:bind>
    Something like that should do the trick. Basically, you need to render the page in the state you want it based on the underlying state of the command object. This is something that is especially true when your pages not only are used to create new things, but also edit existing ones.

    Another completely different approach would be to use Ajax (via DWR or your favorite Ajax toolkit) to populate the fields without submitting the form.

    Christian

  3. #3

    Default

    Hi cnelson,
    Thanks a lot for your help.
    Now it is working fine.
    And i dont know anything abt Ajax or DWR . Will u please help me regarding those.(Resources , good tutotials).
    Thank you very much once again.
    Regards,
    Sasikanth

  4. #4
    Join Date
    Aug 2004
    Location
    San Francisco, CA
    Posts
    66

    Default

    Check out the DWR website... it's pretty fantastic.

    http://getahead.ltd.uk/dwr/

    You can find many resource discussing Ajax simply by googling it. Note however, I would focus on understanding the basic of Spring MVC before you move on to using Ajax or DWR.

    Regards,
    Christian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •