Popular form (Object array)

Asked

Viewed 74 times

0

I have the following object array:

inserir a descrição da imagem aqui

What I have of this object is the index, and I want to use this index to populate a form.

In the function below, fase is the array and ID is the index of the object.

However, as it stands, I can only popular the first index[0].

How can I display information according to the correct index in the fields ?

function _carrega_fase(fase, id) {
    for (var i = 0; i < fase.length; i++) {
        $('#txt_atraso_inicial_alt').val(fase[i].atraso_inicial);
        $('#txt_atraso_final_alt').val(fase[i].atraso_final);
        $('#txt_multa_alt').val(fase[i].multa);
        $('#txt_juros_alt').val(fase[i].juros);
        $('#txt_honorario_alt').val(fase[i].honorario);
    }
}

I hope the form displays the information as below

inserir a descrição da imagem aqui

  • Can you give an example of how HTML is expected to look? As it is now you are over-writing the same elements in HTML.

  • @Sergio, I have one Option Select, that contain the delay range(I will use the index of this select to load the other object information, and popover with the multa, juros and honorario.

  • I put an HTML image of how I hope it looks.

1 answer

1


From what I understand of his code, he is iterating through all the elements, and this overriding the values of the fields at each iteration, this is his proposal?

If the purpose is to take a specific and popular information your form try:

function _carrega_fase(fase, id) {
    $('#txt_atraso_inicial_alt').val(fase[id].atraso_inicial);
    $('#txt_atraso_final_alt').val(fase[id].atraso_final);
    $('#txt_multa_alt').val(fase[id].multa);
    $('#txt_juros_alt').val(fase[id].juros);
    $('#txt_honorario_alt').val(fase[id].honorario);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.