Reputation: 19
Hey guys I have a table that has a main row, a row with a textbox and row with a selectlist that has values of premade comments that when double clicked on need to be populated into the textbox just above it. I am able to get the value of the selected list item into a variable but I can't seem to find the textbox I am looking for. This is all ran by our DB so I am using classes instead of ids and need to find the previous item with the class name. Heres my code, any help would be great.
NOTE: I am not including the document.ready wrapper but it is in my code.
$(".mfValues").dblclick(function () {
var val = $(this).attr("value")
// alert(val);
$(this).prev(".mfTextComments").val(val);
});
<tr><td><textarea class="mfTextComments" runat="server" cols="20" rows="2" ></textarea></td></tr>";
<tr><td><select runat=\"server\" style=\"height:20px;\" title=\"Please select a comment from this list by double clicking the comment or create your own in the text area above.\" size=\"4\">
<option class="mfValues" value="Value1"\">Value1</option>
<option class="mfValues" value="Value2"\">Value1</option>
<option class="mfValues" value="Value3"\">Value1</option>
</select></td></tr>
Upvotes: 0
Views: 378
Reputation: 1614
You were almost there, just need to get out of the < tr > :
$(".mfValues").dblclick(function() {
var $this = $(this),
val = $this.val();
$this.closest('tr').prev().find(".mfTextComments").val(val);
});
Upvotes: 1