在选择"框"中设置选定的值来自输入字段中的值

时间:2015-07-07 07:10:57

标签: jquery html select input

我希望这是一个相当简单的问题,但我还没有找到任何解决方案。我有一个cms系统,我通过常规表单上传不同的东西。相对基础。当我上传了一个项目时,我也无法编辑。这一切都有效。当您添加项目时,您需要选择此项目分配给的一个或多个业务伙伴。这是通过选择(多个)字段完成的,并且该值存储在输入字段中。现在,当我去编辑项目时,在输入字段中显示值(以逗号分隔)。

如果这些值在输入字段中,我想隐藏此输入字段并将select(multiple)字段中的值设置为selected。

我希望我的简单JSFiddle可以澄清它。

http://jsfiddle.net/ovwoaqmo/

<form>
<table class="webform" border="0" cellpadding="2" cellspacing="0">
    <tbody>
        <tr>
            <td>
                <label for="CAT_Custom_5">Partner</label>
                <br>
                <select id="CAT_Custom_5" class="cat_dropdown" multiple="" style="width: 200px;" name="CAT_Custom_5">
                    <option value="test1">test1</option>
                    <option value="test2">test2</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                <label for="CAT_Custom_5">Partner</label>
                <br />
                <input maxlength="4000" name="CAT_Custom_5" id="CAT_Custom_5" class="cat_textbox" value="test1,test2" type="text">
            </td>
        </tr>
        <tr>
            <td>
                <input class="cat_button" value="Submit" id="catcustomcontentbutton" type="submit">
            </td>
        </tr>
    </tbody>
</table>

我知道这两个字段具有相同的ID,这基本上是因为它们是相同的字段,也许这会导致我的问题,或者这可能是一件好事,我不太确定。

非常感谢任何提示或帮助:)

UPDATE /编辑:

我认为这可以解决我的问题: http://jsfiddle.net/4EVBL/16/ 我只需要它在输入字段中用逗号分隔值。 对此有何帮助? :)

2 个答案:

答案 0 :(得分:1)

您好现在可以尝试这个

$(document).ready(function(){
    
    $('#CAT_Custom_5').on('change', function(){
      var some = $(this).val();
        
       
        
        $('#CAT_Custom_6').val(some);
    
    });
    
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<form>
    <table class="webform" border="0" cellpadding="2" cellspacing="0">
        <tbody>
            <tr>
                <td>
                    <label for="CAT_Custom_5">Partner</label>
                    <br>
                    <select id="CAT_Custom_5" class="cat_dropdown" multiple="" style="width: 200px;" name="CAT_Custom_5">
                        <option value="test1">test1</option>
                        <option value="test2">test2</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="CAT_Custom_6">Partner</label>
                    <br />
                    <input maxlength="4000" name="CAT_Custom_6" id="CAT_Custom_6" class="cat_textbox" value="" type="text">
                </td>
            </tr>
            <tr>
                <td>
                    <input class="cat_button" value="Submit" id="catcustomcontentbutton" type="submit">
                </td>
            </tr>
        </tbody>
    </table>
</form>

答案 1 :(得分:0)

APPS = a b c

a_OBJ = x.o y.o z.o
b_OBJ =  p.o q.o r.o
c_OBJ = s.o t.o k.o

all: $(APPS)    
$(APPS):
    @echo $($@_OBJ)

<强> Demo