简体   繁体   English

根据SELETLIST选择填充2个表单字段

[英]Populating 2 form fields based on SELETLIST selection

This is driving me crazy. 这真让我抓狂。 I have a form with 2 fields. 我有一个包含2个字段的表格。

<select name="serviceDescription" id="serviceDescription" onchange="PopulateDescriptionsField();"/> </select>    

I populate the selectList from a CFC call via JQuery. 我通过JQuery从CFC调用中填充了selectList。 That part works. 那部分起作用。 I have a second field: 我有第二个领域:

<input name="descriptionEdit" id="descriptionEdit" size="50">

I would like to set the value of descriptionEdit to the whatever value is selected in the serviceDescription selectlist. 我想将descriptionEdit的值设置为serviceDescription selectlist中选择的任何值。

I cant seem to figure this out. 我似乎无法弄清楚。

With Jquery is: 用jQuery是:

$('body').on('click','#serviceDescription',function() {
    var value = $('#serviceDescription').val();
    $('#descriptionEdit').attr('value',value);
});

have a look in to below code to edit selected option in the serviceDescription list and it may help you to implement the same. 请查看以下代码以编辑serviceDescription列表中的选定选项,它可能有助于您实现相同的功能。

 $('#serviceDescription').change(function(){ var optValue = $(':selected',this).text(); $('#descriptionEdit').val(optValue); $("#descriptionEdit").keyup(function() { var value = $( this ).val(); var newOptval = $( "#descriptionEdit" ).text( value ); $(':selected','#serviceDescription').text(value).val(value); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <select name="serviceDescription" id="serviceDescription"> <option value='service1'>service1</option> <option value='service2'>service2</option> <option value='service3'>service3</option> <option value='service4'>service4</option> <option value='service5'>service5</option> <option value='service6'>service6</option> <option value='service7'>service7</option> <option value='service8'>service8</option> </select> <input name="descriptionEdit" id="descriptionEdit" size="50"> 

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

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