1

I have a little script that allow me to paste a value into different inputs.

<input name="BOO_Price">
<a id="repeatPrice">Repeat</a>
<input name="BOO_Price">
<input name="BOO_Price">
<input name="BOO_Price">
<input name="BOO_Price">


$('#repeatPrice').on('click', function(e) {
    e.preventDefault();
    var price = $(this).prev('input').val();
    $('input[name=BOO_Price]').val(price);
});

It works perfectly.

But now my inputs form are like this.

<input name="BOO_Price[]">

But this is not working:

$('input[name=BOO_Price[]]').val(price);

Ideally, I do not want to had some id or another sort of classes.


Could you please help ?

F__M
  • 1,518
  • 1
  • 19
  • 34

1 Answers1

2

Wrap the attribute value with quotes since value contains meta-characters.

$('input[name="BOO_Price[]"]').val(price);

Or escape the meta-character using \\.

$('input[name=BOO_Price\\[\\]]').val(price);
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188