It is possible to assign the value of a JavaScript variable, to one in ASP

0

I would like to know if it is possible to assign a variable in JavaScript to ASP ?

Example:

Dim ASP
var JS;

ASP = 1
JS = 2;

ASP = JS
Response.Write ASP ' saida deveria ser 2 e
    
asked by anonymous 17.06.2014 / 14:06

3 answers

5

JavaScript is rendered by the browser and ASP is rendered on the server before it is delivered to the user.

Under these conditions, the answer is No, it is not possible.

You would have to use a Javascript to send the information by POST or GET to an ASP page, so you capture the value by request and store it in the ASP variable.

The Inverse (Storing value of an ASP variable in a JS variable) is possible by doing only:

<script type="text/javascript">
    var x = <%=y%>;
</script>
    
18.07.2014 / 20:54
0

If you are doing javascript for you to call the variable in ASP you should do it as follows:

'Bloco ASP    
Dim ASP
ASP = 1

'Bloco Javascript
<script>
   var JS;
   JS = 2;
'<%=ASP%>' = JS;    
</script>
    
16.12.2014 / 15:27
0

Try to pass the value of the JS variable by InnerHtml to a hidden field and then retrieve it in ASP by Request.

Here is an example of what it would look like:

'Mandando o valor da variavel por JS:
document.getElementById("variavel").innerHTML = "Valor da Variavel JS";

'Campo que receberá o valor do JS.
<input type="hidden" id=variavel name=variavel> 
    
23.10.2017 / 21:41