Write file in . ASP with JAVASCRIPT conditions

Asked

Viewed 380 times

1

How do I write a file. ASP if a condition in JAVASCRIPT?

NOTE: I can already write files in . ASP quiet.

Below the font piece as example:

<script>

if(1 == 2) { // ISSO É FALSO, PORTANTE ELE DEVE IR PARA O ELSE, POREM ELE FAZ TODO ASP 
    <% 
     oStream.WriteLine "ESCREVE LINHA 2" 

    If (1 = 1) Then 'IF DO ASP, SE 1 = 2, ELE NÃO ESCREVE , ESTÁ OK
        oStream.WriteLine "ESCREVE LINHA 3"

    End If
    %>

} else {
    <% oStream.WriteLine "ESCREVE FIM" %>
}  

So when the javascript condition is false, it does not respect, and does all ASP.

The result of my file is:

...

WRITE LINE 2 /THIS SHOULD NOT HAVE

WRITE LINE 3 // NEITHER THIS

END WRITER ...

I tried to color the entire font for you to test, but I can’t, give a bug in the editor.

Actual source:

if (frm['MAPA'].window.ChecarDentroDoPonto('VEICULOS', '{<%=rs("VeiculoID")%>-<%=rsPosicao("VeiculoLogID")%>}', '{<%=strChaveRotaP%>}') == false) {
    document.write('<input type="hidden" name="SQL" value="UPDATE VeiculosLogsAuxiliar SET RotaP=\'A\' WHERE PrefixoView=\'<%=rs("PrefixoView")%>\' AND VeiculoLogID=<%=rsPosicao("VeiculoLogID")%>">');

    <% If IsNull(strEmailNew) = False Then
        If InStr(1, strEmailNew, "@") > 0 Then %>

            document.write('<input type="hidden" name="AlertaEmailVeiculoID" value="<%=rs("VeiculoID")%>">');
            document.write('<input type="hidden" name="AlertaEmailAlerta" value="ROTAP<%=lngRotaPID%>-<%=lngPontoIDAtual%>">');
            document.write('<input type="hidden" name="AlertaEmailEmail" value="<%=strEmailNew%>">');
            document.write('<input type="hidden" name="AlertaEmailTitulo" value="<%=strEmpresa & " - ALERTA - " & rsPosicao("DtLog")%>">');
            document.write('<input type="hidden" name="AlertaEmailMensagem" value="<%="Cliente: " & rs("NomeFantasia") & "<br>" & "Veículo: " & rs("VeiculoID") & " - " & rs("Placa") & " - " & rs("Descricao") & "<br>" & "Atrasado na rota \'" & strRotaPDescricao & "\'" %>">');

        <%
        End If
    End If
    %>

</script>

1 answer

2

The Problem:

<script>
if(1==2)
{
alert('entrou na condicao 1');
<%
Response.Write("ASP: condicao01")
%>
}
else
{
alert('entrou na condicao 2');
<%
Response.Write("ASP: condicao02")
%>
}
</script>

In theory what do you think will appear on the screen? the answer is a javascript error and maybe a alert2

the way out is something like this

<script>
if(1==2)
{
alert('entrou na condicao 1');
ASP: condicao01
}
else
{
alert('entrou na condicao 2');
ASP: condicao02
}
</script>

Because?

Because first the ASP is processed on the server, and written its html. then sent to the browser and ai the javascript is executed by the browser...ie the ASP has been processed before...

You should do the same validation in ASP or would prefer to do otherwise

<%
if 1 = 1 then
   <script>
        //colocar o script javascript aqui
   </script>
else
   <script>
        //colocar o script javascript aqui
   </script>
end if
%>

so the server processes and only sends one or other javascript script...tries to post the whole code so I can give the solution, here I passed only logic and why.

If you really have to validate first in js, call an external page that saves the log. something like:

 <script>
    if(1==2)
    {
       $("#idElemento").load('gravaLog.asp?formato=1');
    }
    else
    {
       $("#idElemento").load('gravaLog.asp?formato=2');
    }
    </script>

you can also call different pages, etc, etc. So it will work.

  • understood, but I have to do the condition in JS even, because I’m doing an integration with google MAPS, then I need to draw on the map a vehicle (in JS), and check in (JS) if the drawing is within the point, I will try to post a part of the code:

  • 1

    postei: ROYAL SOURCE, I edited the doubt

  • humm then does the following.. if(1=1) { $("#idElemento"). load('gravaLog01.Asp'); } Else { $("#idElement"). load('gravalog02.Asp'); }

  • in real source I want to replace Document.write with oStream.Writeline in ASP

  • edited the original answer

  • got it, thanks. But I think I’ll do using Activexobject("Scripting.Filesystemobject"), then I write in JS even, What do you think of this solution? Like, it’ll only work on IE, but since it’s an internal monitor, no problem.

  • Excellent answer, well explanatory, congratulations.

  • vandrebr1 do not forget to mark as response

Show 3 more comments

Browser other questions tagged

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