views:

19

answers:

1

I am using the code below. Problem is that every time I select the option it duplicates all the options and the list shows all the options again.

Here is the code:

if(x > 50){ 
    var i, j; 
    j = 0;               
    for(i=0; i < x; i++){                  
        if(i%50==0){ 
             $('#startRecord').append(  
             $('<option></option>').val(i).html((j+1)+'-'+(j+=50)));           
        } 
    }              
    $('#dropDownSpan').css('visibility', 'visible');  
}   

for x = 121, it shows this on the first run:

<option value=0>1-50</option> 
<option value=50>51-100</option> 
<option value=100>1-121</option> 

but when I select an option it reloads the page and then shows these options:

<option value=0>1-50</option> 
<option value=50>51-100</option> 
<option value=100>1-121</option> 
<option value=0>1-50</option> 
<option value=50>51-100</option> 
<option value=100>1-121</option> 

and if I do it a third time...it appends more and so on.

What can I do to prevent that from happening?

thanks

A: 

solved it using this var i, j=0, y=0; //check how manyblock of 50s we have. 1 per 50 records. Last block doesnt have to have all 50 for(r=0; r< x; r+=50){ if(r%50==0){ y++; } } and then adding this if($('#startRecord').children('option').length < y+1)