tags:

views:

26

answers:

2

How can I undo the grey-out if the select row was removed? Also, when there are several rows added, I want to remove only the row corresponding to that "Remove" button and not the others. I guess, my main concern is how can I know which added row has been removed, when the "remove" button is clicked. Please help. Many thanks in advance.

$('#btn').live('click',function() {
   $("#table_name tr:first").before("<tr><td class='c'><input type='hidden' name='a_name' value='" + a + "'>" + a + "</td><input type='button' class='delete' value='Remove'></td></tr>");
   $("#a option:selected").attr("disabled", true);
});
$('#table_name td .delete').live('click',function(){
   // here I want to once again enable the selection
   attr("disabled", false);
   $(this).parent().parent().remove();
});
<select id="a" name="a">
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</option>
</select>
<input id="btn" class="button" type="button" value="Add" />
A: 

perhaps

$(...).removeAttr("disabled");
orip
+1  A: 

Replace this:

// here I want to once again enable the selection
   attr("disabled", false);

With something like:

// Grab the value of the corresponding input
var val = $(this).prev('td').find('input[name=a_name]').val();
// Re-enable the corresponding select option
$('select#a option[value='+val+']').removeAttr('disabled');

You have to use the value from the hidden input to relate it with the select option element.

jwal
Thank you for your answer. It works only if I've added one row, but what if I have several rows added, and I want to remove one of them. How can I keep track of the individual rows and re-enable a particular one?
DGT
Do you have a page to look at? Without looking at it, I can't really picture what you are trying to do exactly.
jwal
Hi jwal, Here is what I'm trying to do. http://jsfiddle.net/N2jyy/2/ I'd appreciate your help.
DGT
Thanks jwal. I found the answer here: http://jsfiddle.net/nick_craver/S2FrE/
DGT