views:

338

answers:

1

My requirement is explain below,

I am having Arraylist in "DAO" class which contains n number of customer names.and I have set that ArrayList in "domain object" and using that "domain object" in jsp page to display the customer name.

I am using session scope in jsp page like below,

<c:set var="listCustomer" value="${ItemDataResponse.dataItemsList[0].listCustomers}" 
scope="session"/>
<c:set var="CustomerData" value="${ItemDataResponse.dataItemsList[1]}" scope="session"/>


  <div  id="my_jpmorgan">

    <table border="0" width="100%" bgcolor="">
       <tr valign="top" class="lnav">
         <td width=100%">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="paddingLeft" bgcolor="">
         <tr>
             <td>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="">
                    <tr>
                       <td valign="top" height="1px" align="left">
                             <span class="pageHeading_DarkBlue">
                                <c:out value="${CustomerData.customerName[0]}"/>
                             </span>
            </td>

          </tr>
         <tr>
          <td align="right"> 
            <select name="singleSelect" onchange="javascript:onchangeFun(this);"> 
              <c:forEach var="Customer" items="${listCustomer}" >
                  <option value=""> <c:out value="${Customer}" /></option>
               </c:forEach>
             </select>      
           </td>
         </tr>
       </td>
     </tr>
 </table>
</div>

While logging the application every first time the first customer name from ArrayList should display in top of jsp page. and then after loading jsp page

The thing is i have to display customer name in top of jsp page when i click anyone of the customer name from the drop down menu (ie.. if i click xxx customer in drop down menu that selected xxx customer name should display in top of jsp page).

I am able to display drop down menu with all the cusotmers name inside it(names getting from ArrayList) but not able to display the customer name in top of jsp page when i select customer name from drop down menu..

please modify my pasted code if necessary. and also if possible send me some sample codes

Note: i am using JSTL tags (my requirement is that).

In above jsp code

                     <c:out value="${CustomerData.customerName[0]}"/>

line should display customer name in top of jsp page when i selected from dropdown menu(currently not working fine) and below lines display drop down window with customers name from ArrayList(working fine)

  <select name="singleSelect" onchange="javascript:onchangeFun(this);"> 
    <c:forEach var="Customer" items="${listCustomer}" >
         <option value=""> <c:out value="${Customer}" /></option>
               </c:forEach>
             </select> 
+2  A: 

It look like that your problem is the unawareness of how HTML forms and JavaScript work.

There are two ways:

  1. Submit the form with the dropdown to the server side. The selected customer will be set as request parameter with the name singleSelect (the dropdown's name).

    <form>
        <select name="singleSelect" onchange="this.form.submit()">
            ...
    

    And display the selected customer accordingly:

    <c:out value="${param.singleSelect}" />
    
  2. Use JavaScript to get the selected customer and set it in the HTML element you'd like to display the customer name in.

    <select name="singleSelect" onchange="showSelectedCustomer(this)">
    

    with this JS function

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

    and this placeholder where you'd like to show the selected customer in:

    <span id="currentCustomer"></span>
    

See also:

BalusC
@BalusC.. As per your suggestion i am using onchange() but the thing is, in onchange="showSelectedCustomer(this)" if i pass current object how can i retreive the selected value in script. i tried but gone in vain. please help me
Manu
This is done in the script function example. The current object is available as `dropdown` variable and how to get the selected value is shown in `var selectedCustomer` line.
BalusC
@BalusC..Everything now working fine.thanks for your help
Manu
@BalusC..i need one more clarification.. at first shot i am displaying all customers in drop down,after clicking anyone customer name the page is refreshing with doing some other stuffs. The thing is after refreshing page i need to display the same customer name as selected still (which i selected before refreshing the page) and remaining all other customer name in drop down... any ideas?
Manu