Go get value to table and put in form

2

This is the table has the fields the purpose is to click the edit button and clicking the jquery statement that I put above will fill in the fields automatically referring to the line that was clicked

This is what I want to get in the records of the table and put them in a modal in input text and I used the following code (It is working but only for <input type="text"> but for textarea and combobox does not work and that's what I want)

<script>
    $('body').on("click", ".edit", function() {
        $('#alterar_ID').val($(this).parents('tr').find('td').eq(0).text());
        $('#alterar_si').val($(this).parents('tr').find('td').eq(0).text());
        $('#alterar_nome').val($(this).parents('tr').find('td').eq(1).text());
        $('#alterar_data').val($(this).parents('tr').find('td').eq(2).text());
        $('#alterar_duracao').val($(this).parents('tr').find('td').eq(3).text());
        $('#alterar_tipo').val($(this).parents('tr').find('td').eq(4).text());
        $('#alterar_relatorio').val($(this).parents('tr').find('td').eq(5).text());

    });
</script>

That is, clicking a button in the table will fetch the values corresponding to the indexes and place them in the modal inputs. My question is the following and if I want to put in a textarea or leave selected a combobox ?

    
asked by anonymous 19.12.2017 / 21:17

1 answer

2

The problem is that when you get the text in the table, it is not matching to the value in the combobox because the text captured from the table comes with spaces, and will not match the value of select .

To resolve this, always use .trim() , which will clear the spaces:

$('#alterar_tipo').val($(this).parents('tr').find('td').eq(4).text().trim());
    
20.12.2017 / 01:30