views:

53

answers:

1

Hello Every1,the issue is regarding how to retain the selected value in Combobox during pagination. "i have a combobox which has some values,whenevr i select 1 value then according to the value selected the Records per page will be defined BUT whenever i navigate to next page then the value in combobox gets reset to first value". Here's the piece of code..

For Combobox

   print qq[<td>Records PerPage</td>];
   print qq[<td><select id="combo1" onchange="getCombo1(this.options
     [this.selectedIndex].value,$pageNum)"><option value="">Select</option><option
      value="2">2</option><option value="4" >4</option><option 
      value="6">6</option><option value="10">10</option></select></td></tr>];

The Javascript

  <script type="text/javascript">
function getCombo1(offset,pagenumber)
 {
        var val1=pagenumber;
        var val2=offset;
       window.location="UsersList.cgi?pageNum="+val1+"&offset="+val2
 }

The Pagination Code

    if ( $pageNum > 0 ) {
         print qq[<tr><td><a href="UsersList.cgi?
         pageNum=0&offset=$offset&SortBy=$SortBy&SortOrder=$SortOrder">|&lt;</a></td>];
    $pageN  = $pageNum - 1;
    print qq[<td><a href="UsersList.cgi?
     pageNum=$pageN&offset=$offset&SortBy=$SortBy&SortOrder=$SortOrder">&lt;</a></td>];
                      }
    else
      { 
    print q[<td><span class="currentpage">|&lt;</span></td>];
    print q[<td><span class="currentpage">&lt;</span></td>];
       }
  if ( $pageNum < ( $numofPages - 1 )) {
    $pageN  = $pageNum + 1;
    print qq[<td><a href="UsersList.cgi?
       pageNum=$pageN&offset=$offset&SortBy=$SortBy&SortOrder=$SortOrder">&gt;</a>
       </td>];
    $tempnumpage=$numofPages-1;
    print qq[<td><a href="UsersList.cgi?
       pageNum=$tempnumpage&offset=$offset&SortBy=$SortBy&SortOrder=$SortOrder">&gt;|
       </a></td>];
    }
    else {
       print q[<td><span class="currentpage">&gt;</span></td>];
       print q[<td><span class="currentpage">&gt;|</span></td>];
          }
       my  $temppageNumber=$pageNum+1;
      print qq[<td><b> $temppageNumber of $numofPages pages</b></td>];

Please Help Me find the solution.Thank You

+2  A: 

Your Combobox printing code needs to print "selected" attribute in the appropriate "<option>".

For that, you need to loop through the option values, printing them one by one in a loop; and on an appropriate one (matching your $offset) print the "selected" attribute. The way it's usually done is similar to this:

print qq[<td>Records PerPage</td>];
print qq[<td><select id="combo1" onchange="getCombo1(this.options
  [this.selectedIndex].value,$pageNum)"><option value="">Select</option>];

foreach my $value (2, 4, 6) {
    my $selected = ($offset == $value) ? "selected" : "";
    print qq[<option value="$value" $selected>$value</option>];
}
print qq[</select></td></tr>];
DVK
Thanks a lot,its working perfectly fine.;-).thank you once again.
SUSH