开发者

Build an Input value based on other multiple input values

I have a set of form fields that exist like

<input type="text" name="item" id="item" value="">
<input type="text" name="desc" id="desc" value="">
<input type="text" name="place" id="place" value="">
<input type="hidden" name="somecode" name="somecode" value="1">
<input type="hidden" name="op" id="op" value="0">
<input type="hidden" name="result" id="result" value="">

What I need is for the result field to be auto updated as data is entered in the other fields with a double - added between them, so the result would look like

Item--desc--place--somecode--op

The site I have uses jquery for other javascript on the site so if that is useful to g开发者_运维技巧et the desired result then great (but not essential)


This should work assuming you can add a class to each item. Although I'm not sure it will trigger when the hidden value changes, do you need it to?

$('input.test').change(function() {
    $('#result').val($('#item').val() + "--" + $('#desc').val() + "--" + $('#place').val() + "--" + $('#somecode').val() + "--" + $('#op').val());
});

JSFiddle Example

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜