Calling javascript function from within a Classic ASP block

Asked

Viewed 1,971 times

0

How do I run a javascript function from inside a classic Asp block. The js function is not in the same file, it is out, 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;"
%>
  • I made a comment on the goal, about downvote and I’m getting downvotes without even deserving, that is, out of pure hatred, but I’m still going to continue with my opinion about these guys here. They’re hiding, some cowards.

  • Certainly it is a problem of Stackoverflow. It has the link of the topic, I want to follow!

  • I think the negative votes of this question are coming because it has no code or exemplification of what you want (which I don’t think is a reason to vote negative). And yes, it’s a real problem...

  • But think about me. It’s a very general question, I don’t see why have a code. Like I said, I have an Asp page and I need to call a js function, but I’ll take one of the many times that this will happen, I’ll block the code.

  • This is not possible.

  • 2

    It was not I who denied it. But I agree with you. Vote negative, does not say why and nobody edits.

  • The platform itself gives a "reminder" to consider a comment while negative. It is common for me to see some downvotes and no comments. I wonder if, in our reality, it would not be necessary to force a comment to use downvote, unfortunately.

  • vote up, clear and objective question, is that it is fashionable to give downvote.. rs

Show 3 more comments

3 answers

1

Is not possible.

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

It would be possible to do the opposite javascript call or receive variable Asp, ex

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

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

alert('valor_da_variavel');

So, unfortunately it is not possible for you to do this even programming ASP Classic with vbscript or javascript.

0

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

But it is possible that you include the call to a function JS within an element HTML, as long as you have the script with function in the document is it a JS external included or not.

So off the if(MINHA_FUNÇÂO_JS_AQUI) that definitely won’t work another problem in your code is that you concatenated the excerpt from JS in the element HTML wrongly:

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

the correct 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();" />

0

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

in your example code I checked that src="" was incorrect.

follows below the way of entering javascript code in ASP in 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 way out:

<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>

Browser other questions tagged

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