Answers for "jquery get multiple input values by name"

0

jquery get multiple input values by name

<input name="titles[]">
<input name="titles[]">
<button>submit</button>

// click handler
function onClick(event) {
  var titles = $('input[name^=titles]').map(function(idx, elem) {
    return $(elem).val();
  }).get();

  console.log(titles);
  event.preventDefault();
}

// attach button click listener on dom ready
$(function() {
  $('button').click(onClick);
});
Posted by: Guest on May-19-2021

Code answers related to "jquery get multiple input values by name"

Code answers related to "Javascript"

Browse Popular Code Answers by Language