07-24-2023, 10:05 AM
My home automation system only allows communication through JSCRIPT that runs on the SPS embedded IIS as ASP code. The old web interface was just on HTML and JSCRIPT. I need to move to HTML, CSS and JS with Bootstrap, but for data access I need to stick with JSCRIPT (ASP).
Reading data from asp variables is working easy, set it with a static value as well, **but to set asp variables through JS DYNAMICLY is where I struggle. **
I'd like something likd WritetoASP(A_Var, J_Var) where A_Var has the name of the ASP var and J_Var the value to be passed.
I'm sure that all the experts here do have a solution for me.
Here is a sample Code that shows the challenge.
```
<% @LANGUAGE="JSCRIPT"%>
<%
var A_Var=88;
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>ASP JS HTML Test</title>
<script runat="server" type="text/javascript">
var J_Var, Par="A_Var";
/* use the real asp variable name, returns the right ASP value */
J_Var = <%=A_Var %>;
document.write ('J_Var = '+J_Var+'<br>');
/* write a static value to the asp variable, writes the right value to ASP */
<%A_Var = 66;%>;
document.write ('A_Var = '+<%=A_Var%>+'<br>');
/* try to store and use the asp variable name in a JS variable, fails */
J_Var = <%="Par"%>;
document.write ('J_Var = '+J_Var+'<br>');
/* using eval to execute the asp command, fails */
J_Var = eval('<%="Par" %>');
document.write ('J_Var = '+J_Var+'<br>');
/* eval execute string generated in a variable, fails */
/* the replace is needed, otherwise JS interpretes the ASP tag */
Par="'Ü%="+Par+"%>'";
document.write ('Par = '+Par+'<br>');
J_Var = eval(Par.replace(/Ü/g,"<"));
document.write ('J_Var = '+J_Var+'<br>');
</script>
</head>
<body>
</body>
</html>
This is the result:
J_Var = 88
A_Var = 66
J_Var = A_Var
J_Var = A_Var
Par = 'Ü%=A_Var%>'
J_Var = <%=A_Var%>
```
Reading data from asp variables is working easy, set it with a static value as well, **but to set asp variables through JS DYNAMICLY is where I struggle. **
I'd like something likd WritetoASP(A_Var, J_Var) where A_Var has the name of the ASP var and J_Var the value to be passed.
I'm sure that all the experts here do have a solution for me.
Here is a sample Code that shows the challenge.
```
<% @LANGUAGE="JSCRIPT"%>
<%
var A_Var=88;
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>ASP JS HTML Test</title>
<script runat="server" type="text/javascript">
var J_Var, Par="A_Var";
/* use the real asp variable name, returns the right ASP value */
J_Var = <%=A_Var %>;
document.write ('J_Var = '+J_Var+'<br>');
/* write a static value to the asp variable, writes the right value to ASP */
<%A_Var = 66;%>;
document.write ('A_Var = '+<%=A_Var%>+'<br>');
/* try to store and use the asp variable name in a JS variable, fails */
J_Var = <%="Par"%>;
document.write ('J_Var = '+J_Var+'<br>');
/* using eval to execute the asp command, fails */
J_Var = eval('<%="Par" %>');
document.write ('J_Var = '+J_Var+'<br>');
/* eval execute string generated in a variable, fails */
/* the replace is needed, otherwise JS interpretes the ASP tag */
Par="'Ü%="+Par+"%>'";
document.write ('Par = '+Par+'<br>');
J_Var = eval(Par.replace(/Ü/g,"<"));
document.write ('J_Var = '+J_Var+'<br>');
</script>
</head>
<body>
</body>
</html>
This is the result:
J_Var = 88
A_Var = 66
J_Var = A_Var
J_Var = A_Var
Par = 'Ü%=A_Var%>'
J_Var = <%=A_Var%>
```