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