在select上,动态填充textarea-jQuery

在select上,动态填充textarea-jQuery,jquery,forms,wordpress,gravity,Jquery,Forms,Wordpress,Gravity,我正在使用WordPress的Gravity表单插件,我正在尝试让一个选择菜单动态更新文本区域中的文本。我对jQuery非常陌生,如果您能帮助我理解如何使代码正常工作,我将不胜感激 <script type="text/javascript"> $(document).ready(function() { $('#input_27').change(function() { var divetext = $('#input_27')

我正在使用WordPress的Gravity表单插件,我正在尝试让一个选择菜单动态更新文本区域中的文本。我对jQuery非常陌生,如果您能帮助我理解如何使代码正常工作,我将不胜感激

<script type="text/javascript"> 
    $(document).ready(function() {

        $('#input_27').change(function() {
            var divetext = $('#input_27').val();
            var divewords = '';
            if (divetext == 'Standard') {
            divewords = 'All Ye Surface Sailors, aviators, fossil-fuelers, landlubbers, and other innocents Know ye and Mark ye that from (date) to (date) the inner depths of my subaqueous realm were visited by a very large black denizen.  On careful examination by my mermaids this great black fish was identified as (Name of submarine). I am informed that among the distinguished on board at that time was (Recipient name). By this my decree, this Submariner is awarded and shall bear in perpetuity the honored title of Deep Diver and shall be accorded all the perquisites and privileges that befit this exalted status.';
            }
            else if (divetext == '1st Dive') {
            divewords = 'All Ye Surface Sailors, aviators, fossil-fuelers, landlubbers, and other innocents Know ye and Mark ye that from (date) to (date) the inner depths of my subaqueous realm were visited by a very large black denizen.  On careful examination by my mermaids this great black fish was identified as (Name of submarine). I am informed that among the distinguished on board for their 1st Dive was (Recipient name). By this my decree, this Submariner is awarded and shall bear in perpetuity the honored title of Deep Diver and shall be accorded all the perquisites and privileges that befit this exalted status.';
            }
            else if (divetext == 'Last Dive') {
            divewords = 'All Ye Surface Sailors, aviators, fossil-fuelers, landlubbers, and other innocents Know ye and Mark ye that from (date) to (date) the inner depths of my subaqueous realm were visited by a very large black denizen.  On careful examination by my mermaids this great black fish was identified as (Name of submarine). I am informed that among the distinguished on board for their last time was (Recipient name). By this my decree, this Submariner is awarded and shall bear in perpetuity the honored title of Deep Diver and shall be accorded all the perquisites and privileges that befit this exalted status.';
            }
            else if (divetext == 'Honorary Submariner') {
            divewords = 'All Ye Surface Sailors, aviators, fossil-fuelers, landlubbers, and other innocents Know ye and Mark ye that from (date) to (date) the inner depths of my subaqueous realm were visited by a very large black denizen.  On careful examination by my mermaids this great black fish was identified as (Name of submarine). I am informed that among the distinguished on board at that time was (Recipient name). By this my decree, this Submariner is awarded and shall bear in perpetuity the honored title of Deep Diver and shall be accorded all the perquisites and privileges that befit this exalted status.';
            }
            else {
            divewords = 'All Ye Surface Sailors, aviators, fossil-fuelers, landlubbers, and other innocents Know ye and Mark ye that from (date) to (date) the inner depths of my subaqueous realm were visited by a very large black denizen.  On careful examination by my mermaids this great black fish was identified as (Name of submarine). I am informed that among the distinguished on board at that time was (Recipient name). By this my decree, this Submariner is awarded and shall bear in perpetuity the honored title of Deep Diver and shall be accorded all the perquisites and privileges that befit this exalted status.';
            }
            $("#input_20").val(divewords);    
        });​
    });
</script> 
代码也位于:

输入_27-选择菜单的ID。 输入_20-文本区域的ID

简而言之,我希望文本区域中的语言根据他们从下拉列表中选择的项目而改变

提前谢谢

请试试这个

请替换此代码:

var divetext = $('#input_27').val();


看起来对我来说应该有用。有什么问题吗?当我进行选择时,文本区域中没有显示任何内容。我可以链接表单,但它是一个多页表单,而且特定字段非常深入,因此需要进行PITA。好的,尝试调试:如果您还没有firebug,那么获取它并与firefox一起使用。然后将以下行console.logdivetext放在var divetext=$'input_27'.val;看看这个值是多少。问题可能就在那里。或者,尝试手动设置divetext,以便找出问题所在—if条件或divetext值的设置。控制台中没有显示有关divetext的任何内容。使用firebug的控制台,在底部的命令行中键入:console.log$'input_27'.val;。如果为空,则您的输入_27不传递任何值,您发现了问题。发布html结构也会有所帮助。
var divetext = $('#input_27:selected').text();