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;   
            }
        });
    }
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.
– iamdlm
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.
– Pietro Rey