开发者

how to sync textfields in html

I have multipul input fields on a page, a few of them are type="textfield" and some of those textfields i want to group, so that if i type somethi开发者_Python百科ng into one of them it propergates to the rest within that group.

I have tried using the same name as radio buttons work like this, but that doesn't seem to work. i have looked around the net but cannot find any examples.

does anyone know how to do this, or anywhere which tells you how?

Regards

chris


I don't think it's possible with pure html, have you tried using JavaScript? I would look into jQuery to set up event handlers for that.

$('textbox1').change(function(o) {
    $('textbox2').val($(o).val());
}

Will react to all changes of textbox1 and replicate the value to textbox2. Untested code, only an approach.


jQuery since version 1.7 offers a convenient way to handle several events by using the .on() handler - method:

$(document).ready(function() {
    $('#textbox1').on('keypress keyup change', function(event) {
            $('#textbox2').val(event.target.value);
    });
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜