How to reamin my search value on combo at jsp after form submit? -


pls me ,my problem using search in jsp application. search staff name . after filling these fields , controller search , results displayed on same page below search fields. problem want after submission , search values of search fields should remain on search form was.

i using :

<select name="requesttype" id="select" class="form-control" onchange="dropdownonchange(this);">     <option value="">&lt;&lt; select 1 &gt;&gt;</option>     <option value="all">all</option>                                 <option value="staffname">staff name</option>     <option value="leavetype">leave type</option>     <option value="year">year</option> </select>     <div class="col-sm-1">     <button type="submit" class="btn btn-primary">search</button> </div> 

use javascript select search item once page loaded.

  1. at backend, receive search value name requesttype, , when response, set value request, such request.setattribute("requesttype", seachedvalue)
  2. in jsp page, create input hidden next select element store requesttype response. <input type="hidden" value="${requesttype}"/>.
  3. at bottom of jsp page or use jquery ready function, input[hidden] value, , use javascript select option. var searchtype = $('select[name="searchtype"]').next('input').value(); $('select[name="searchtype"] option').each(function(){ $(this).removeattr('selected'); if($(this).value() === searchtype) { $(this).attr('selected', 'selected'); } });

Comments