I’ve noticed that you can set javascript variables using ASP code. For example:
var test = "<%response.write(number)%>"
I was wondering if other types of ASP code can work in javascript, such as if statements or while loops. For Example:
function test1()
{
count = 0;
<%if number = 1 then%>
count = count + 1;
<%end if%>
}
function test2()
{
count = 0;
<%index = 0
do while index < 10 %>
count = count +1;
<%index = index +1
loop%>
}
I am relatively new to web development and programming so I’m not sure if this is possible. If this does not work, is there any way I can get around this or a different way to code it?
Any tips or advice would be greatly appreciated.
As I say in my comment, it’s really important to understand the difference between client-side and server-side processing in things like ASP, ASP.NET, PHP, etc.
As you appear to know, the javascript is run on the client-side (i.e. the browser). The server-side does processing of the ASP, ASP.NET, PHP, etc and then sends information (HTML, Javascript, etc) to the browser.
You can indeed do the following code that you have written…
But instead of the SERVER doing the calculation 10 times, the server will create the line 10 times and send it to the browser…
… meaning the CLIENT run javascript will do the calculation 10 times.
Depending on exactly what you need the code to do will depend on whether the code should be run client-side or server-side… it’s pretty much impossible to tell you which without knowing what you’re trying to do.
Hope this helps