Call javascript function from within a Classic ASP block

0

How do I perform a javascript function from within a classic asp block. The js function is not in the same file, it is outside, in another file.

<%
if(MINHA_FUNÇÂO_JS_AQUI)
response.write "<img align='middle' width='24' height='24' name='img_negociacao_local_internacao' id='img_negociacao_local_internacao' src='onClick='javascript:abrirNegociacaoTipoAtendimento();' >&nbsp;"
%>
    
asked by anonymous 16.01.2017 / 15:45

3 answers

1

Not possible.

ASP Classic is interpreted by the server and sent the html already processed to the client. Javascript is processed only on the client.

It would be possible to do otherwise javascript call or receive asp variable , ex

alert('<%=variavel%>');

because actually when processing occurs first on the server it would return to the client

alert('valor_da_variavel');

So, unfortunately you can not do this even by programming ASP Classic with vbscript or javascript.

    
17.01.2017 / 19:54
0

Hello, use the double quotes "" this way the ASP will interpret normally, if you use 'apostrophe' ASP understands that it is a comment.

In your sample code I noticed that src="" was incorrect.

Here's how to insert javascript code into ASP into a variable:

<%
response.write "<img align=""middle"" width=""24"" height=""24"" name=""img_negociacao_local_internacao"" id=""img_negociacao_local_internacao"" src=""digite o endereço da imagem"" onClick=""javascript:abrirNegociacaoTipoAtendimento();"" >&nbsp;"
%>

This is the output:

<html><body>
<img align="middle" width="24" height="24" name="img_negociacao_local_internacao" id="img_negociacao_local_internacao" src="" onclick="javascript:abrirNegociacaoTipoAtendimento();">&nbsp;
</body></html>
    
23.01.2017 / 01:35
0

Can not put JS directly connected to ASP so forget to use it as part of logic because how ASP and JS are processed is different, ie if you try to put your JS function as a condition for a loop repetition or even a simple conditional ( IF ) it will not work because the ASP is interpreted by the server and only then on the client side will the JS be processed.

However, you may include the call to a function JS within a HTML element, as long as you have the function script in the document it does not include an external% of enclosed or not.

Then it was the JS that definitely will not work Another problem in your code is that you concatenated the if(MINHA_FUNÇÂO_JS_AQUI) snippet in the JS element in the wrong way:

<%= "<img src='onClick='javascript:abrirNegociacaoTipoAtendimento();' />" %>

The correct one would be:

<%= "<img onClick='javascript:abrirNegociacaoTipoAtendimento();' />" %>

Or

<%= "<img onClick=""javascript:abrirNegociacaoTipoAtendimento();"" />" %>

This code will be interpreted by the server and will create the following HTML :

<img onclick="javascript:abrirNegociacaoTipoAtendimento();" />
    
22.09.2017 / 15:29