html - jquery appending value to input field -
i'm trying add dynamically 1 input field values jquery. passed value won't appended target. code looks follows
//on click popup modal form $(document).on('click', '#form', function(e) { e.preventdefault(); $('<div></div>').load($(this).attr('href')).dialog({ title: $(this).attr('title'), //autoopen: false, modal: true, draggable: true, width:900, position: ['top',50], close: function(event, ui) { $(this).dialog('destroy').remove() } }); //this value should appended 1 of input field, value exists on alert not getting appended $('input#inputprepend cashback').val( $(this).closest('tr').children('td.cashback').text() ); });
notes:
//this value picked jquery datatable clicked row $(this).closest('tr').children('td.cashback').text() //this input field getting created inside of modal $('input#inputprepend cashback')
html
<div class="formrow fluid"> <span class="grid12"> <span class="grid2"><label class="form">cashback</label></span> <span class="grid3"> <div class="input-prepend"> <span class="add-on">€</span> <input style="width:120px;height:30px; position relative; top:-10px"type="text" id="inputprepend cashback" type="text" readonly="readonly" value="" /> </div> </span> </span> </div>
in example:
$('input#inputprepend cashback').val( $(this).closest('tr').children('td.cashback').text() );
$(this)
refers document, not $('input#inputprepend cashback')
you can use instead:
var $input = $('input#inputprepend cashback'); $input.val( $input.closest('tr').children('td.cashback').text() );