For the current code,when the button's clicked, it'll get the value from the done input and display them to the 3 input field respectively.
Let say i'd like to change the value in the done input field, and when the value is updated, the old values from the 3 input fields will be replaced by the new. Now, the updated value just added after the original value instead of replacing it. What's wrong with my code guys?
$(".ok").on('click', function() {
var set = $(this).closest('tr').find('.done').val();
if ( set ){
$(this).closest('tr').find('.text').each(function(){
$(this).val( $(this).val() + set );
})
}
});
<table>
<tr>
<td>
<input type="button" value="ok" class="ok"></td>
<td>done<input type="text" value="100" class="done" \> </td>
<td>text1<textarea class="text">hi</textarea> </td>
<td>text2<textarea class="text">hello</textarea> </td>
<td>text3<textarea class="text">sup</textarea> </td>
</tr>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
$(this).val( $(this).val() + set );and write this$(this).val( set );because$(this).val( $(this).val() + set );is adding values beside input field