Вопрос

the Html code :

<tr class="item-row">
   <td>
     <input type="button" class='del' value="" style="z-index:16; background-image:url(../images/delete.png); background-repeat:no-repeat; background-position:left center; text-align:right;"/>
   </td>
   <td>
     <input type="button" name="pilihItem[]" value="i" id="pilihItem" class="pilihItem">
   </td>
   <td>
     <input type="text" id="nama_item" name="nama_item[]" value="" style="width: 200px;">
   </td>
</tr>
<tr class="item-row">
   <td>
     <input type="button" class='del' value="" style="z-index:16; background-image:url(../images/delete.png); background-repeat:no-repeat; background-position:left center; text-align:right;"/>
   </td>
   <td>
     <input type="button" name="pilihItem[]" value="i" id="pilihItem" class="pilihItem">
   </td>
   <td>
     <input type="text" id="nama_item" name="nama_item[]" value="" style="width: 200px;">
   </td>
</tr>

the jquery code to open child window:

$("#pilihItem").click(function(){
        var id = 1;
        var name = $(this).prev().attr("name");           
        var url = "../formItem.php?id=" + id + "&name=" + name;

        window.open(url, 'Pilih Item', 'location=1,status=1,scrollbars=1,resizable=no,width=800,height=300'); 
    });

the jquery code to set value to the parent window :

window.opener.$("#nama_item").val($.trim(nama_item));

enter image description here

the problem : I cannot set the value of #nama_item textbox where the button #pilihItem clicked from. its always set the textbox on the first row. any help will be much appreciated.

Это было полезно?

Решение

You're using an ID to select the input when instead you should be using something unique.

You either need to change the ID to be unique (they should be unique in the DOM anyway), or change the name of the checkbox to something like...

<input type="text" name="nama_item[1]" value="" style="width: 200px;">

And change your JS in the pop-up to use this name instead of the ID...

window.opener.$("input[name='nama_item[1]']").val($.trim(nama_item));

Другие советы

change the ID to be unique or change the checkbox name using array= name="item_name[1]"

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top