Consulting input data in the database - ASP + SQL

Asked

Viewed 66 times

0

Good guys, I’m more than a beginner in ASP and JS and I’m hitting here to do something that should be simple.

I have an input which will be filled with a value "xxAMSxxxx/xx" and needed to validate this value in the bank and once it is true, show and fill a piece of a form that will be saved later. I tried to do this but I didn’t succeed.

PS: I was able to at least block the button in the form div.

function mostraCampos() {
  if (document.getElementById("dsAmsReference").style.display === "none") {
    document.getElementById("dsAmsReference").style.display = "block";
  } else {
    document.getElementById("dsAmsReference").style.display = "none";
  }
}

<div class="input-control select novospan2 floatForm-left">
  Reserva AMS
  <input name="dsAmsReference" id="dsAmsReference" placeholder="Digite aqui a Ref" type="text">
</div>      

<% 

dim dsAmsReference 

dsAmsReference  = codificar(request("dsAmsReference")) 'não segura o valor


DIM ID_CD_CLIENTE,DS_AMS_REFERENCE,DS_VESSEL,DS_VOYAGE,DS_ORIGEM,DS_DESTINO,DS_ORIGEM_COLETA,DS_DESTINO_COLETA,NM_PESSOA,NR_CPF_CNPJ,DS_ENDERECO,DS_COMPLEMENTO,NM_CIDADE,NM_ESTADO,NR_CEP,NR_PREFIXO,NR_DDD,NR_TELEFONE

DIM NR_NETWEI

    objBD.SQL = "EXEC PR_DRAFT_DRAF_s @FUNCAO='S35', @DS_AMS_REFERENCE='"&dsAmsReference&"', @ID_CD_LOGIN='"&Session("ID_CD_LOGIN")&"'"
    'response.write(objBD.SQL)
    'response.end()
    objBD.executaSQlBasico                          
    if not objBD.RS.eof then 

        DS_AMS_REFERENCE            = objBD.RS("DS_AMS_REFERENCE")
        DS_VESSEL                   = objBD.RS("DS_VESSEL")
        DS_VOYAGE                   = objBD.RS("DS_VOYAGE")
        DS_ORIGEM                   = objBD.RS("DS_ORIGEM")
        DS_DESTINO                  = objBD.RS("DS_DESTINO")    
        DS_ORIGEM_COLETA            = objBD.RS("DS_ORIGEM_COLETA")
        DS_DESTINO_COLETA           = objBD.RS("DS_DESTINO_COLETA")
        NM_PESSOA                   = objBD.RS("NM_PESSOA")
        NR_CPF_CNPJ                 = objBD.RS("NR_CPF_CNPJ")
        DS_ENDERECO                 = objBD.RS("DS_ENDERECO")
        DS_COMPLEMENTO              = objBD.RS("DS_COMPLEMENTO")
        NM_CIDADE                   = objBD.RS("NM_CIDADE")
        NM_ESTADO                   = objBD.RS("NM_ESTADO")
        NR_CEP                      = objBD.RS("NR_CEP")
        NR_PREFIXO                  = objBD.RS("NR_PREFIXO")
        NR_DDD                      = objBD.RS("NR_DDD")
        NR_TELEFONE                 = objBD.RS("NR_TELEFONE")
        'response.write(objBD.SQL)
        'response.end()
    else
        objBD.LimpaRecordSet 
        objBD.FecharConexao
        response.Redirect("inicio.asp")         
        response.end()
    end if      

%>
 <!--#include file="teste-draft-js.asp"-->
<div class="input-control margBottom50 text span2 ">    
  <input type="submit" value="Validar Ref" onclick="mostraCampos();completaDraft(dsAmsReference,'<%=DS_AMS_REFERENCE%>')"/>
</div>

Below the JS to complete the form.

function completaDraft(dsAmsReference) { 

        dataString = "acao=CPD&dsAmsReference="+dsAmsReference;
        dataString = dataString+"&dsAmsReference="+dsAmsReference;
        //alert(dataString); return false;
        $.ajax({  
            type: "POST",  
            url: cfgUrl+"draft-acoes.asp",  
            data: dataString,  
            dataType: "json",
            beforeSend: function(){
                PaginaAguardeAbre();
            },
            success: function(json) {  
                PaginaAguardeFecha();
                if( json.result.bool() ){
                    ExibeMensagem('Sucesso',"Status da processo alterado com sucesso!","",2500);
                    //$("#formFiltro").submit();
                }else{
                    ExibeMensagem('Aviso',json.erro,"",5000);                       
                }
                return false;
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                alert(XMLHttpRequest.responseText);         
                enviaLogError(XMLHttpRequest.status, XMLHttpRequest.responseText,this.url,this.data);
                verificaLogado(XMLHttpRequest.status, XMLHttpRequest.getResponseHeader("URL_REDIRECT"));
                PaginaAguardeFecha();               
                ExibeMensagem('Erro',"Desculpe, mas ocorreu um erro. Por favor, tente novamente.","",4000);
                RequestEnviado = 0;
                return false;   
            }
        });
    }

inserir a descrição da imagem aquiError after Script Change

Validarinput and Select code made by him.

   <% 
Response.Charset = "ISO-8859-1"
Response.Expires = 0
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache" 

dim dsAmsReference

set     objBD   = new ConectaBD 'INSTÂNCIA A CLASSE 
call    objBD.AbrirConexao


dsAmsReference  = codificar(request("dsAmsReference"))

If PAG_TOP = "" Then
    PAG_TOP = 1
End If

SQL = "EXEC PR_DRAFT_DRAF_s                                             "
SQL = SQL & " @funcao               = 'S02'                             "
SQL = SQL & ",@DS_AMS_REFERENCE     = '"&dsAmsReference&"'              "
SQL = SQL & ",@ID_CD_LOGIN  = '"&SESSION("ID_CD_LOGIN")&"' "
'response.write(SQL)
QueryToJSON(objConJson, SQL).Flush
objConJson.close
Set objConJson = Nothing
%>  

------------ SQL below -----------

if @funcao = 'S02'
begin
    SELECT
        DS_AMS_REFERENCE
    FROM TB_BOOKING_BOOK
    WHERE DS_AMS_REFERENCE = @DS_AMS_REFERENCE
    ORDER BY DS_AMS_REFERENCE
end
  • Do not just make an ajax request to the server with the value of this input and validate returning true or false as the result? Just copy this code to complete the form and just change the url.

  • I would do the same code as the completeDraft but changing the url to what? I didn’t understand it well, because this completeDraft serves to call the form fields.

1 answer

1

If I understood correctly I left the input just so:

<input type="submit" value="Validar Ref" onclick="mostraCampos();"/>

And in this method would make an ajax request similar to the one below, where the Validarinput method should return true or false depending on the field dsAmsReference is valid or not, and only then show and fill in the form. That’s it?

function mostraCampos() {
  $.ajax({
    type: "POST",
    url: "ValidarInput",
    data: $("#dsAmsReference").val(),
    success: function(result) {
      if (result == true) {
        document.getElementById("dsAmsReference").style.display = "block";
        completaDraft($("#dsAmsReference").val());
      } else {
        document.getElementById("dsAmsReference").style.display = "none";
      }
      return false;
    }
  });
}
  • That’s right, man, but how do I validate dsAmsReference in the bank? Create a new Asp with the name Validarinput where it makes a select in the database and validates that what was typed is inside the table? E on the other input method, it is there because when validated dsAmsReference and the form appearing some data comes straight from the database for the user to complete the remaining fields.

  • That’s exactly it @Pietrorey, try it and if you have any questions put it there.

  • So @iamdlm every time I click on the button it returns me an error as if I had a problem with a script on another page. I do not know if my select is wrong or if it is the page(Validarinput) that is not done correctly, I will post the code of both, if you can help me again would be grateful.

Browser other questions tagged

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