Updating a select option using jQuery -


i have form when updated, need change name of item in select input. i'm using loop through options, i'm having trouble figuring out how change text value. here tried

$('#groupid option').each(function () {                     if ($(this).val() == currently_editing_group_id)                         $(this).attr('text', $('#newgroupname').val());                 }); 

here select input

<select id="practicegroupid" name="groupid">       <option value="5">test group 1</option>       <option value="6">test group 2</option> 

you can use base dom properties .text , .value of <option> element, this:

$('#practicegroupid option').each(function () {   if (this.value == currently_editing_group_id)     this.text = $('#newgroupname').val(); }); 

or in selector:

$("#practicegroupid option[value='"+currently_editing_group_id+"']").each(function () {   this.text = $('#newgroupname').val(); }); 

note want #practicegroupid selector, since # id , not name.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -