简体   繁体   English

需要通过选择框,多个文本框和选择列表的值填充文本框

[英]Need to populate textbox via value of selectbox, multiple textboxes and selectlists

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. 这都是由我们的数据库运行的,因此我使用的是类而不是ID,并且需要找到带有类名的上一项。 Heres my code, any help would be great. 这是我的代码,任何帮助都会很棒。

NOTE: I am not including the document.ready wrapper but it is in my code. 注意:我没有包括document.ready包装器,但是它在我的代码中。

   $(".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>

You were almost there, just need to get out of the < tr > : 您快到了,只需要离开<tr>即可:

$(".mfValues").dblclick(function() {
    var $this = $(this),
        val = $this.val();
    $this.closest('tr').prev().find(".mfTextComments").val(val);
});​

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM