Create a filter from a field value

Asked

Viewed 55 times

0

Good morning

I created two fields for selection. And one of them has a list of values. When selected the value, in another field, which will also have a list, I need to appear only the corresponding values.

In the example below, the code on the side relates the description on the right side. That way when I select code 411075145 I want the other selection field to look like the Agreement, Deposit and INSS Guide descriptions

411075145 - Agreement

411075145 - Deposit

411075145 - INSS Guide

Below the follows the code:

function  CarregarRelativo() {
    $('#Relativo').empty();
    AddDropDownItem('Relativo', '', '');
    
    var 
    var data = GetListItems('02FC4BE9-B056-486D-A9C6-3743DF5F9257',"?$orderby=Title");
    
    if (data != null) {
        data.forEach(function(item) {
            AddDropDownItem('Relativo', item.DescricaoContaContabil,item.DescricaoContaContabil);
        });
    }
}
  • 1

    It’s a little confusing your question, you have a checkbox with code and another with another according to the selected code, I do not understand. Could explain better ?

  • Sorry, come on, let’s go. have two checkbox , at checkbox1 this the codes and at checkbox2 should list the texts according to the code selected at checkbox1.

1 answer

0


By your code can not help because I do not know what you are doing in Adddropdownitem.

But follow an example that gets the code from one and adds the description to another.

See if it fits.

$(document).ready(function(){
		var ListCodigosDescricao = [];
    ListCodigosDescricao.push({Codigo: 12345151, Descricao:'Formulario 1'});
    ListCodigosDescricao.push({Codigo: 84574848, Descricao:'Formulario 2'});
    ListCodigosDescricao.push({Codigo: 45487548, Descricao:'Formulario 3'});
    
    var selectCodigos = $('#selectCodigos');
    
    $.each(ListCodigosDescricao, function(i, el){
    	selectCodigos.append('<option value="' + i + '">' + el.Codigo + '</option>');
    });
    
  	$("#selectCodigos").change(function(){
    	var itemDaLista = ListCodigosDescricao[this.value];
        $('#selectDescricao').append('<option value="">' + itemDaLista.Descricao + '</option>');
  	});
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<label>Selecione um Código:</label>
<select id='selectCodigos'>
  <option></option>
</select>
<br/>
<label>Selecione uma Descrição:</label>
<select id='selectDescricao'>
  <option></option>
</select>

Browser other questions tagged

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