Jump to content
Fórum Script Brasil
  • 0

Trazendo Dados do Ajax para dentro do input no ASP


Tiárli Oliveira

Question

Bom dia Galera!

Estou iniciando a programar, e estou com um problema com um ajax. Basicamente, tenho minha página .asp que tenho meu formulário com os inputs, e quero trazer dados para dentro deles quando mudo o valor de uma combo. Até aí tudo bem, ativo a funcao no onchange, ele dispara o ajax, ele faz o comando (traz os dados no select através de uma store procudere) e os dados eu jogo pro asp na div que estipulei.

O problema é que trazendo para um único input, ele joga certo, mas quando tento jogar várias informações em outra div, ele não joga os valores dentro dessas divs, ele simplismete criar inputs novos com os valores da pesquisa.

Aqui tenho a pag.ajax

<!--#include file="conexao.asp"-->

<% 
id_maquina             = request("id_maquina")
data_caixa_aberto     = request("data_caixa_aberto")
id_sala                = request("id_sala")




    cComando1 = "exec sp_justnew_erp_ve_frente_caixa_coleta_medidores "
    cComando1 = cComando1 & " @operacao                = 44"
    cComando1 = cComando1 & ",@idusuario               = '"& session("id_usuario") &"' "
    cComando1 = cComando1 & ",@idsala               = '"& session("id_sala") &"' "
    cComando1 = cComando1 & ",@data                       = '"& FormataDataBanco(data_caixa_aberto)&"' "
    cComando1 = cComando1 & ",@idmaquina            = '"& id_maquina &"' "
    'Response.Write(cComando1)
    set rsquery1 = Conn.execute(cComando1)



%>                
                    <tr>
                                <td width="600" colspan="2">
                                    <table>                                
                                    
                                        <tr>
                                            <td align="left" colspan="2"><b>CÓPIAS</b></td>
                                            <td align="left" colspan="2"><b>SCANNER</b></td>
                                        </tr>
                                                <tr>
                
                                                    <td width="132">Saldo Inicial:</td>
                                                    <td>
                                                    <input type="text" id="qtde_copias_ini" name="qtde_copias_ini" value="<%=rsquery1("qtde_copias_ini")%>"></td>
                                                    <td width="132">Saldo Inicial:</td>
                                                    <td>
                                                    <input type="text" id="qtde_scanner_ini"name="qtde_scanner_ini" value="<%=rsquery1("qtde_scanner_ini")%>"></td>    
                                                </tr>        
                                                <tr>
                                                    <td width="132">Medidor Final:</td>
                                                    <td>
                                                    <input type="text" onblur="java script:ajax_enviar(this.value);java script:ajax_enviar2(<%=rsquery1("id_coleta")%>);"id="qtde_copias" name="qtde_copias"  value="<%=rsquery1("qtde_copias")%>"></td>
                                                    <td width="132">Medidor Final:</td>
                                                    <td>
                                                    <input type="text" id="qtde_scanner" name="qtde_scanner" value="<%=rsquery1("qtde_scanner")%>"></td>
                                                </tr>                                        
                                                <tr>
                                                    <td width="132">Erro:</td>
                                                    <td>
                                                    <input type="text"  onblur="java script:ajax_enviar4(this.value);" id="qtde_copias_erradas" name="qtde_copias_erradas" value="<%=rsquery1("qtde_copias_erradas")%>"></td>
                                                    <td width="132">Erro:</td>
                                                    <td>
                                                    <input type="text" onblur="java script:ajax_enviar5(this.value);" name="qtde_scanner_errados" value="<%=rsquery1("qtde_scanner_errados")%>"></td>
                                                </tr>                                
                                                <tr>
                                                    <td width="132">Internas:</td>
                                                    <td>
                                                    <input type="text"  onblur="java script:ajax_enviar6(this.value);" id="qtde_copias_int" name="qtde_copias_int" value="<%=rsquery1("qtde_copias_int")%>"></td>
                                                    <td width="132">Internas:</td>
                                                    <td>
                                                    <input type="text"  onblur="java script:ajax_enviar7(this.value);" id="qtde_scanner_int" name="qtde_scanner_int" value="<%=rsquery1("qtde_scanner_int")%>"></td>
                                                </tr>
                                                <tr>
                                                    <td width="132">Saldo Final:</td>
                                                    <td>
                                                    <input type="text"  id="saldo_final" name="saldo_final" value="<%=rsquery1("qtde_copias_liq")%>"></td>
                                                    <td width="132">Saldo Final:</td>
                                                    <td>
                                                    <input type="text" id="saldo_final_scan" name="saldo_final_scan" value="<%=rsquery1("qtde_scanner_liq")%>"></td>    
                                                    </tr>
                                    </table>
                                </td>
                    </tr>
E aqui tenho minha pag.asp com o formulario onde quero jogar os dados do ajax
<head>
<meta http-equiv="Content-Language" content="pt-br">
<style>
<!--
table        { font-family: Tahoma; font-size: 10pt; color: #FFFFFF }
input        { font-family: Tahoma; font-size: 9pt; text-align:right}
-->
</style>
&lt;script language="javascript">
<!--
function ajax_Operador(id_maquina,data_caixa_aberto)
{
var oHTTPRequest = createXMLHTTP(); 
oHTTPRequest.open("post", "fechamentocaixa_ajax.asp", true);
oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
oHTTPRequest.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
oHTTPRequest.setRequestHeader("Pragma", "no-cache");
oHTTPRequest.onreadystatechange=function() {
if (oHTTPRequest.readyState==4){
document.all.divOperador.innerHTML = oHTTPRequest.responseText;
}
}
oHTTPRequest.send("id_maquina=" + id_maquina + "&data_caixa_aberto=" + data_caixa_aberto);
}

function ajax_enviar(qtde_copias)
{
    document.form1.qtde_copias.value     = qtde_copias;
    
}

function ajax_enviar2(id_coleta)
{
    document.form1.id_coleta.value     = id_coleta;
    
}
function ajax_enviar3(qtde_scanner)
{
    document.form1.qtde_scanner.value     = qtde_scanner;
    
}
function ajax_enviar4(qtde_copias_erradas)
{
    document.form1.qtde_copias_erradas.value     = qtde_copias_erradas;
    
}
function ajax_enviar5(qtde_scanner_errados)
{
    document.form1.qtde_scanner_errados.value     = qtde_scanner_errados;
    
}
function ajax_enviar6(qtde_copias_int)
{
    document.form1.qtde_copias_int.value     = qtde_copias_int;
    
}
function ajax_enviar7(qtde_scanner_int)
{
    document.form1.qtde_scanner_int.value     = qtde_scanner_int;
    
}

function ajax_Saldo(id_maquina,data_caixa_aberto)
{
var oHTTPRequest = createXMLHTTP(); 
oHTTPRequest.open("post", "fechamentocaixa_ajax2.asp", true);
oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
oHTTPRequest.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
oHTTPRequest.setRequestHeader("Pragma", "no-cache");
oHTTPRequest.onreadystatechange=function() {
if (oHTTPRequest.readyState==4){
(document.getElementById('divConteudo').innerHTML) = oHTTPRequest.responseText;
}
}
oHTTPRequest.send("id_maquina=" + id_maquina + "&data_caixa_aberto=" + data_caixa_aberto);
}

//-->
</script>
</head>

<body bgcolor="#000000" onKeyPress="press(event.keyCode);" <%=onload%>>
 <table border="0" width="913" height="420" style="border-collapse: collapse">
    <form method="post" action="fechamentocaixa.asp" name="form1">
    <input type="hidden" name="acao" value="fechar">
    <input type="hidden" name="id_coleta" value="<%=qtde_copias%>">
    <input type="hidden" value="<%=id_coleta%>">
    <input type="hidden" value="<%=qtde_copias_erradas%>">
    <input type="hidden" value="<%=qtde_scanner_errados%>">
    <input type="hidden" value="<%=qtde_copias_int%>">
    <input type="hidden" value="<%=qtde_scanner_int%>">
    
    

    
        <tr>
            <td height="428" width="936" align="left" valign="top">
                <img border="0" src="img/logo.png" width="280" height="50"><br>
                <br>
                <%
                If retorno > 0 Then
                    If msg <> "" Then
                %>            
                <div align="center">
                <br>
                    <table align="center" border="1" width="100%" bordercolorlight="#B2DC4D" bordercolordark="#B2DC4D" bgcolor="#CCE297" style="border-collapse: collapse" cellspacing="5" cellpadding="5">
                        <tr>
                            <td>
                                <b><font face="Arial" size="2" color="#40550D">
                                <img border="0" src="img/accept.png" width="16" height="16"> <%=msg%></font></b>
                            </td>
                        </tr>
                    </table>
                </div>
                <%
                    End If
                Else
                    If msg <> "" Then
                %>                        
                <div align="center">
                <br>
                    <table align="center" border="1" width="100%" style="border-collapse: collapse" bordercolorlight="#C82820" bordercolordark="#C82820" bgcolor="#E7928D" cellspacing="5" cellpadding="5">
                        <tr>
                            <td><b><font face="Arial" size="2" color="#C82820">
                            <img border="0" src="img/cancel.png" width="16" height="16"> <%=msg%></font></b></td>
                        </tr>
                    </table>
                </div>
                <%
                    End If
                End If
                %>                    
                <table width="610">
                    <tr>
                        <td style="font-size: 8pt;" colspan="2"> </td>
                    </tr>                                                                                            
                    <tr>
                        <td width="132">Data do caixa aberto:</td>
                        <td width="468">
                            <select size="1" name="data" style="width:200px;">
                                <%
                                While not rsquery3.eof
                                    If Trim(data) = Trim(rsquery3("data")) Then
                                %>
                                    <option value="<%=rsquery3("data")%>" selected><%=rsquery3("data")%></option>
                                <%
                                    Else
                                %>
                                    <option value="<%=rsquery3("data")%>"><%=rsquery3("data")%></option>
                                <%
                                    End If
                                    rsquery3.movenext
                                Wend
                                %>
                            </select></td>
                        
                    </tr>                                                                                    
                    <tr>
                        <td width="132">Máquina:</td>
                        <td width="468">
                        <font size="1" color="#FFFFFF">
                        <select size="1" name="id_maquina" style="width:200px;" onchange="ajax_Operador(this.value,'<%=data%>');ajax_Saldo(this.value, '<%=data%>')">
                        <%
                        While not rsquery1.eof
                            If Trim(id_maquina) = Trim(rsquery1("id_maquina")) Then
                        %>
                            <option value="<%=rsquery1("id_maquina")%>" selected><%=rsquery1("maquina_descricao")%></option>
                        <%
                            Else
                        %>
                            <option value="<%=rsquery1("id_maquina")%>"><%=rsquery1("maquina_descricao")%></option>
                        <%
                            End If
                            rsquery1.movenext
                        Wend
                        %>
                        </select></font>
                        </td>                        
                    </tr>
                    <tr>
                        <td width="132">Operador:</td>
                            <td width="468">
                                <div id="divOperador">
                                    <font size="1">
                                    <input type="text" id="descricao_operador" name="descricao_operador">
                                </div>
                            </td>
                    </tr>
                    <font size="1" color="#FFFFFF">
                    <tr>
                        <td width="132"> </td>
                        <td width="468"> </td>
                    </tr>                                        
                    
                    <tr>
                                <td width="600" colspan="2">
                                    <table>
                                    <div id="divConteudo">    
                                        <tr>
                                            <td align="left" colspan="2"><b>CÓPIAS</b></td>
                                            <td align="left" colspan="2"><b>SCANNER</b></td>
                                        </tr>
                                            
                                            <tr>
                                                
                                                <td width="132">Saldo Inicial:</td>
                                                <td>
                                                <input type="text" id="qtde_copias_ini" name="qtde_copias_ini" value="<%=qtde_copias_ini%>"></td>
                                                <td width="132">Saldo Inicial:</td>
                                                <td>
                                                <input type="text" id="qtde_scanner_ini"name="qtde_scanner_ini" value="<%=qtde_scanner_ini%>"></td>    
                                            </tr>        
                                            <tr>
                                                <td width="132">Medidor Final:</td>
                                                <td>
                                                <input type="text" id="qtde_copias" name="qtde_copias"  value="<%=qtde_copias%>"></td>
                                                <td width="132">Medidor Final:</td>
                                                <td>
                                                <input type="text" id="qtde_scanner" name="qtde_scanner" value="<%=qtde_scanner%>"></td>
                                            </tr>                                        
                                            <tr>
                                                <td width="132">Erro:</td>
                                                <td>
                                                <input type="text" id="qtde_copias_erradas" name="qtde_copias_erradas" value="<%=qtde_copias_erradas%>"></td>
                                                <td width="132">Erro:</td>
                                                <td>
                                                <input type="text" id="qtde_scanner_errados" name="qtde_scanner_errados" value="<%=qtde_scanner_errados%>"></td>
                                            </tr>                                
                                            <tr>
                                                <td width="132">Internas:</td>
                                                <td>
                                                <input type="text" id="qtde_copias_int" name="qtde_copias_int" value="<%=qtde_copias_int%>"></td>
                                                <td width="132">Internas:</td>
                                                <td>
                                                <input type="text" id="qtde_scanner_int" name="qtde_scanner_int" value="<%=qtde_scanner_int%>"></td>
                                            </tr>
                                            <tr>
                                                <td width="132">Saldo Final:</td>
                                                <td>
                                                <input type="text" id="saldo_final" name="saldo_final"></td>
                                                <td width="132">Saldo Final:</td>
                                                <td>
                                                <input type="text" id="saldo_final_scan" name="saldo_final_scan"></td>    
                                            </tr>
                                    </div>    
                                    </table>
                                </td>
                    </tr>
                            
                                            
                    <tr>
                        <td width="132"><br>
                        <a href="java script:document.form1.submit();">
                        <font color="#FFFFFF">GRAVAR</font></a></td>
                        <td width="468"> </td>
                    </tr>
                </table>
    </form>

Gostaria de saber uma maneira onde quando ativar minha funcao, trazer os dados de forma dinamica sem refresh com o ajax trazendo examento nos inputs para que eu possa alterar e salvar!

Desde já agradeço, e fico no aguardo de uma ajuda para meu problema.

Tiárli Oliveira

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...