Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery delete 'select option' element value except the second option value

how can i delete the value of each select option element except the second option value :

<select name="_users_id_requester" onchange="submit()">
  <option value="0">-----</option>
  <option selected="" value="774">Asmaa El Habib,Yassine</option>//except this one 
  <option value="779" title="Ahlam Edouiri - U8K8O">Ahlam Edouiri</option>
  <option value="746" title="Ainane Mohamed - MohamedAinane">Ainane Mohamed</option>
</select>

i have tried some thing like this but i don't know how to end it :

$("select[name='_users_id_requester']").each(function(){
  if ( $(this).index() > ..... )
    $(this).attr("value", " ");
});
like image 304
user2077308 Avatar asked Feb 25 '13 22:02

user2077308


2 Answers

You can go like

$("select[name='_users_id_requester'] option").not(":eq(1)").val('');
like image 58
jAndy Avatar answered Oct 21 '22 03:10

jAndy


$("select[name='_users_id_requester'] option").not(":eq(1)").prop('value', '');
like image 33
undefined Avatar answered Oct 21 '22 04:10

undefined