I have a form that loops over the database and displays the form to the user. The user is supposed to change the drop down value to Add Duplicate or Move but in many cases, they will all be the same. so, I’d like to give them a “Copy Down” feature where they can click on an icon. This will fire a function to get the value of the selected input name (just in front of the icon in the same table cell (td) and set the other items in the list to the same value. ID’s are unique and I thought I could get use $(‘#id’).val() to get the value but even that isn’t working.
<tr id="row_653"> <-- this value increments -->
<td>xtipi208_c_dl8453</td>
<td>Dalllas</td>
<td>ibm</td>
<td>SLPAR on p570</td>
<td>2012-04-15</td>
<td>dl8453</td>
<td>mt1933</td>
<td><select name="systemAction_653" id="SystemAction_653" class="systemAction">
<option value="0">Action Required</option>
<option value="copy">Add Dup</option>
<option value="move">Move</option>
</select>
<span class="ui-icon ui-icon-copy vtip replicate" id="select_resource_653" title="Copy this value down the list." style="float: right;" name="systemAction" systemid="653" cntr="13"></span></td>
</tr>
and here is the JS I’m working with:
$('.replicate').live("click",function(){
var nm=$(this).attr('name');
var cntr=$(this).attr('cntr');
var systemID=$(this).attr('systemID');
var vl=$(this).parent().prev().find("select").val();
// alert(nm + ' ' + cntr + ' ' + systemID + ' ' + vl); //for vl, I'm getting undefined
$('[name="'+nm+'"][systemID="'+ systemID + '"]').each(function() {
if ($(this).attr("cntr") >= cntr)
$(this).parent().prev().find("select").val(vl);
});
});
It’s hard to know for sure but it may be as simple as this:
jsFiddle