yigitozmen yigitozmen - 1 month ago 4
Javascript Question

get item from multiple inputs with jquery which have the same name

I am listing items via table then want to change individual names of items.

<td class="tdFileName">
<?php $nameArray = explode(".", $f->file_name); ?>
<input type="text" name="ra_name" class="raName" value="{{$nameArray[0]}}">
<button type="submit" class="btn-warning btnRaName">D├╝zenle</button>
</td>
<td>{{$userName}}</td>


$('.btnRaName').on('click', function (e) {
e.preventDefault();
alert($('.raName').val());
location.reload();
});


When I click the individual button I only get first input's value. How can I fix that?

Answer

On click you need to pick the prev HTML element as it will be the desired input field:

$('.btnRaName').on('click', function (e) {
    e.preventDefault();
    var txt = $(this).prev('input.raName').val();
    console.log(txt);
    location.reload();
});
Comments