javascript - change name of dynamically added select option element -


i dynamically generating dropdowns , allowing them of removed on board dyanmically. time, have encountered error of selection option (dropdown) elements id mismatch. below is.

newly added dropdowns.

select name="cssatapsclient[client_time_window_arr][0]" id="client_time_window_0">/select> select name="cssatapsclient[client_time_window_arr][1]" id="client_time_window_1">/select> select name="cssatapsclient[client_time_window_arr][2]" id="client_time_window_2">/select> select name="cssatapsclient[client_time_window_arr][3]" id="client_time_window_3">/select> 

after dynamically remove them via javascript. (lets removing second one) new ones displayed followings,

select name="cssatapsclient[client_time_window_arr][0]" id="client_time_window_0">/select>     select name="cssatapsclient[client_time_window_arr][2]" id="client_time_window_2">/select>     select name="cssatapsclient[client_time_window_arr][3]" id="client_time_window_3">/select> 

so issue have is, names of dropdowns this, (0,2,3)

cssatapsclient[client_time_window_arr][0],  cssatapsclient[client_time_window_arr][2],  cssatapsclient[client_time_window_arr][3]  

so causing error me , need reorder name , make this, (0,1,2)

cssatapsclient[client_time_window_arr][0] cssatapsclient[client_time_window_arr][1] cssatapsclient[client_time_window_arr][2] 

how can rename these dropdowns name attribute (from 0 how ever dropdows exisiting) ? appreciate reply

edit 1

i tried this, didnt work.

$('#tbl_dynamic_call_dates select').each(function(i){ $(this).attr('name',"cssatapsclient[client_time_window_arr][i]"); }); 

you can reset values using .attr() method:

$('#tbl_dynamic_call_dates select').attr('name', function(i) {    return 'cssatapsclient[client_time_window_arr]['+ +']'; }); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -