2
Use the function onChange="getPeca(1);", where is accessed a JS that feeds the field to the side with the description. This works, if I directly in the field and enter the code and give tab it does the search correctly:
Now, if I search the entire form using an Ajax, it only brings the code, not doing the search linked to the input:
In HTML I use the onChange. Does anyone know if there is another "better function"?
<td><input type = "text" id="codItem1" name = "codItem1" size = 10 maxlength =5 placeholder="Código 1" onChange="getPeca(1);">
Script that feeds the entire form:
/**
  * Função para criar um objeto XMLHTTPRequest
  */
 function CriaRequest() {
     try{
         request = new XMLHttpRequest();
     }catch (IEAtual){
         try{
             request = new ActiveXObject("Msxml2.XMLHTTP");
         }catch(IEAntigo){
             try{
                 request = new ActiveXObject("Microsoft.XMLHTTP");
             }catch(falha){
                 request = false;
             }
         }
     }
     if (!request)
         alert("Seu Navegador não suporta Ajax!");
     else
         return request;
}
//Não executa nada até a execução terminar
var requestActive = false;
function getOrdem() {
    if (requestActive) return;
    requestActive = true;
    // Declaração de Variáveis
    /* Caso for necessário passar mais parametros além do nome
     * basta adicionar uma variável aqui e editar no GET
     */
     var ids = ["equipamento", "descrCC", "parada", "data_inicio", "hora_inicio", "hora_parada", "data_fechamento", "tipo_servico_ficha", "tipo_acao",
                "problema", "responsavel", "mecanico_1", "mecanico_2", "mecanico_3", "mecanico_4", "mecanico_5", "mecanico_6", "tipo_servico_1",
                "tipo_servico_2", "tipo_servico_3", "tipo_servico_4", "tipo_servico_5", "tipo_servico_6", "tipo_acao_1", "tipo_acao_2", "tipo_acao_3",
                "tipo_acao_4", "tipo_acao_5", "tipo_acao_6", "tipo_falha_1", "tipo_falha_2", "tipo_falha_3", "tipo_falha_4", "tipo_falha_5", "tipo_falha_6",
                "data_inicio_1", "data_inicio_2", "data_inicio_3", "data_inicio_4", "data_inicio_5", "data_inicio_6", "data_fim_1", "data_fim_2", "data_fim_3",
                "data_fim_4", "data_fim_5", "data_fim_6", "horas_apro_1", "horas_apro_2", "horas_apro_3", "horas_apro_4", "horas_apro_5", "horas_apro_6",
                "min_apro_1", "min_apro_2", "min_apro_3", "min_apro_4", "min_apro_5", "min_apro_6", "acao_1", "acao_2", "acao_3", "acao_4", "acao_5",
                "acao_6", "obs_1",  "obs_2", "obs_3", "obs_4", "obs_5", "obs_6", "codItem1", "codItem2", "codItem3", "codItem4", "codItem5", "codItem6", "codItem7",
                "codItem8", "codItem9", "codItem10", "codItem11", "codItem12", "codItem13", "codItem14", "codItem15", "codItem16", "codItem17", "codItem18", "codItem19",
                "codItem20", "item_qtde_1", "item_qtde_2", "item_qtde_3", "item_qtde_4", "item_qtde_5", "item_qtde_6", "item_qtde_7", "item_qtde_8", "item_qtde_9",
                "item_qtde_10", "item_qtde_11", "item_qtde_12", "item_qtde_13", "item_qtde_14", "item_qtde_15", "item_qtde_16", "item_qtde_17", "item_qtde_18",
                "item_qtde_19", "item_qtde_20", "infos_complementares"];
    var ordem = document.getElementById("ordem").value; //CAMPO QUE VEM DO INDEX.PHP
    var result = document.getElementById("content"); //DIV DE RETORNO DOS DADOS
    var xmlreq = CriaRequest();
    // Exibe a mensagem de progresso
    //result.innerHTML = '<img src="images/Progresso.gif"/>';
    ids.forEach(function (id) {
        document.getElementById(id).value = 'Aguarde...';
    });
    // Iniciar uma requisição
    // Se for colocar mais variáveis, é aqui. Exemplo: processa.php?txtnome=" + nome + '&admissao=' + admissao
    xmlreq.open("GET", "js/processaOrdem.php?ordem=" + ordem, true);
    // Atribui uma função para ser executada sempre que houver uma mudança de estado
    xmlreq.onreadystatechange = function () {
        // Verifica se foi concluído com sucesso e a conexão fechada (readyState=4)
        if (xmlreq.readyState == 4) {
            // Verifica se o arquivo foi encontrado com sucesso
            if (xmlreq.status == 200) {
                //Se o retorno foi vazio do Oracle
                if (xmlreq.responseText == "") {
                    document.getElementById("ordem").focus();
                    alert("Não existe a ordem!");
                    ids.forEach(function (id) {
                        document.getElementById(id).value = '';
                        document.getElementById("ordem").value = '';
                    });
                //Se encontrou dados
                } else {
                    //Aqui recebe os dados do processa.php, abre e aplica nos campos desejados
                    var dados = JSON.parse(xmlreq.responseText);
                    // função para preencher os campos com os dados
                    ids.forEach(function (id) {
                        document.getElementById(id).value = dados[id];
                    });
                }
            } else {
                result.innerHTML = "Erro: " + xmlreq.statusText;
            }
        }
        requestActive = false;
    };
    xmlreq.send(null);
}
Script that feeds the single field:
/**
  * Função para criar um objeto XMLHTTPRequest
  */
 function CriaRequest() {
     try{
         request = new XMLHttpRequest();
     }catch (IEAtual){
         try{
             request = new ActiveXObject("Msxml2.XMLHTTP");
         }catch(IEAntigo){
             try{
                 request = new ActiveXObject("Microsoft.XMLHTTP");
             }catch(falha){
                 request = false;
             }
         }
     }
     if (!request)
         alert("Seu Navegador não suporta Ajax!");
     else
         return request;
}
//Não executa nada até a execução terminar
  var requestActive = false;
function getPeca(id_campo) {
   if (requestActive) return;
       requestActive = true;
    // Declaração de Variáveis
    /* Caso for necessário passar mais parametros além do nome
     * basta adicionar uma variável aqui e editar no GET
     */
    var codItem = document.getElementById("codItem" + id_campo).value; //CAMPO QUE VEM DO INDEX.PHP
    var result = document.getElementById("content"); //DIV DE RETORNO DOS DADOS
    var xmlreq = CriaRequest();
    // Exibe a mensagem de progresso
    //result.innerHTML = '<img src="images/Progresso.gif"/>';
    document.getElementById("desc_item_" + id_campo).value = "Aguarde...";
    // Iniciar uma requisição
    // Se for colocar mais variáveis, é aqui. Exemplo: processa.php?txtnome=" + nome + '&admissao=' + admissao
    xmlreq.open("GET", "js/ProcessaPecaEdicao.php?codItem=" + codItem, true);
    // Atribui uma função para ser executada sempre que houver uma mudança de estado
    xmlreq.onreadystatechange = function () {
        // Verifica se foi concluído com sucesso e a conexão fechada (readyState=4)
        if (xmlreq.readyState == 4) {
            // Verifica se o arquivo foi encontrado com sucesso
            if (xmlreq.status == 200) {
                //Se o retorno foi nulo ou vazio
                if ((xmlreq.responseText == "null") || (xmlreq.responseText == "")) {
                    alert("Item inexistente! Cadastre antes");
                    document.getElementById("codItem" + id_campo).value = '';
                    document.getElementById("desc_item_" + id_campo).value = '';
                    document.getElementById("codItem" + id_campo).focus();
                //Se encontrou dados
                } else {
                    document.getElementById("item_qtde_" + id_campo).focus();
                    //Aqui recebe os dados do processa.php, abre e aplica nos campos desejados
                    var dados = JSON.parse(xmlreq.responseText);
                    // função para preencher os campos com os dados
                       document.getElementById("desc_item_" + id_campo).value = dados;
                }
            } else {
                result.innerHTML = "Erro: " + xmlreq.statusText;
            }
        }
        requestActive = false;
    };
    xmlreq.send(null);
}
						
It was unclear what you meant by "Now, if I do the whole form search, it only brings the code, not by doing the research linked to the input". Can you elaborate further? Also, enter the code of
getPeca(). The problem may be there.– Pablo Almeida
In fact the getPeca() is bringing all 102 fields I need, but in those inputs, which has another ajax, it doesn’t call. It’s as if the input was fed and he didn’t recognize it as coming from ajax.
– Diego
So there are two scripts that you didn’t put in? You can put both?
– Pablo Almeida
Edited the question
– Diego