0
$(document).ready(function(){
    $('#1, #2').click(function(){
        window.clickedbtnid = $(this).attr('id');
        $( "#table_dialog_1" ).dialog();
    });
    $( "#table_dialog_1" ).find('td').click(function(){ $('#'+window.clickedbtnid).parent().prev().find('input').val($(this).id);
        $( "#table_dialog_1" ).dialog('close');
    })
});

$('#input_'+id).attr('value', $(this).html());

this was closed to what i want but it only pass based on clicked td's text of table on dialog area because what I need is the first td table of dialog window to pass on input tag, and second td and third on link tag element. See my last table in fiddle below, it should look like the table on the main page when dialog window is closed.

see this FIDDLE

bumbumpaw
  • 2,522
  • 1
  • 24
  • 54

1 Answers1

1

I hope this is what you are looking for, I refactored the code a bit, added class clickMe to button, it makes id unnecessary.

the JS code

var clickedButton;
$(document).ready(function(){
$('.clickMe').click(function(){
    clickedButton = this;
    $( "#table_dialog_1" ).dialog();        
});
$( '#table_dialog_1 tr').click(function(){ 
    var  tds = $(this).children();
    $(clickedButton).parent().prev().find('input').val(tds.eq(0).html());
    $(clickedButton).next('a').text(tds.eq(2).html()+','+tds.eq(1).html());
    $( "#table_dialog_1" ).dialog('close');
});
});
mido
  • 24,198
  • 15
  • 92
  • 117
  • Yes, i also looking for code that will disregards `id's`.Thanks. – bumbumpaw Oct 13 '14 at 08:25
  • In this example,im using jquery ui dialog, but will need it in simple window.open("page here"), but thanks. – bumbumpaw Oct 13 '14 at 08:27
  • Hi,why does $(clickedButton).parent().prev().find('input').val(tds.eq(0).html()); always returning null , im using window.open(page.jsp) and not jquiery ui dialog – bumbumpaw Oct 14 '14 at 08:10
  • i am assuming tds is element in the new window, and you are trying to access from parent window, i do not think that is possible, you can look into this http://stackoverflow.com/questions/1830347/quickest-way-to-pass-data-to-a-popup-window-i-created-using-window-open/1830388#1830388, – mido Oct 14 '14 at 08:17
  • so ` $(clickedButton).parent().prev()` not applicable for window.open? – bumbumpaw Oct 14 '14 at 08:54
  • Actually i do have codes opener.window.f1.txtInput1.value = tds.eq(0).html(); but it olny work if table has only one row. – bumbumpaw Oct 14 '14 at 08:57
  • @bumbumpaw without looking at your code, i cannot tell what is wrong, but if you are using a new window, once some row is clicked, you need to call a method of the parent window, and pass the row data to it, and then call window.close(), take a look at this http://stackoverflow.com/questions/9276086/popup-window-to-return-data-to-parent-on-close – mido Oct 14 '14 at 14:12