I am trying to write something that will copy the current <input>s value and enter it into any <input> that start with the same name.<input> names will follow this pattern: price-0, price-1, price-2, upc-0, upc-1, upc-2.So if a user enters a value in <input name=price-0> and hits copy the value should be transferred over to all input whos name start with priceThis is the code I've written:$(document).on('click', '.--copy', function () {    var input_name = $(this).closest('div').find('input').attr('name').split('-')[0];    $('input[name^=' + input_name + ']').val($(this).closest('div').find('input').val());});A fiddle to make everyones life easier: http://jsfiddle.net/6jGLD/I feel like there are too many selectors being called upon and the code is somewhat difficult to read.
Is there a simpler way of copying and pasting one inputs value into other input with the same name
javascript;jquery
One minor improvement I can think of is to create a variable to hold the input element since the element is used twice like$(document).on('click', '.--copy', function () {    var $input = $(this).closest('div').find('input'), input_name = $input.attr('name').split('-')[0];    $('input[name^=' + input_name + ']').val($input.val());});Demo: Fiddle