简体   繁体   中英

Bulk form controls with JavaScript/jQuery

I'm trying to build a form with bulk/master controls which will take the value from one input field and insert it into multiple others when a button (anchor tag) is clicked.

I've looked high and low for information on how is can be done, but cannot find anything that's of any help, and there surely has to be something out there!

I'm not asking for someone to actually code this for me, but rather point me in the right direction.

Thanks

The val function is what you're looking for

To copy the value from input source , to all the inputs with class destination , you would use:

$("input.destination").val($("#source").val());

In addition to what Adam wrote, I generally use custom attributes if I need to, for instance, point one HTML element at another, eg

<input id='source' copyto='destination' />

then:

$('#' + $('#source').attr('copyto')).val($('#source').val());

or a function:

function copyIt(fromID) {
  var destID = '#' + $(fromID).attr('copyto');
  $(destID).val($(fromID).val());
}

and usage:

copyIt('#source');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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