[thelist] ASP passing value to javascript for loop

Chris Blessing webguy at mail.rit.edu
Mon Mar 18 14:40:07 CST 2002


Gary-

I have to do this a lot.  One cool thing about asp is that even though you
may have a block of code encapsulated by <SCRIPT> tags, you can still
response.write in that block.

That being said, I prefer to do it this way:

<SCRIPT LANGUAGE="JavaScript">
var myVar = "<% = request.form("formVarName") %>";

for(var i=0; i<myVar; i++){
	...
}
</SCRIPT>

Of course if you're not going to use the ASP var more than once, you may not
need a variable declaration like I have here, but I like to keep my code
organized. =)

Chris Blessing
webguy at mail.rit.edu
http://www.330i.net

> I am trying to pass a value to javascript from an ASP page and am stuck.
> I have passed the value within the ASP by creating a hidden input
> field with
> the value assigned to it.
>
> I.E. input type=hidden name=repeatval value=response.write(subcounter).
>
> The problem is, I need to use this value in a javascript for loop.
>
> i.e. for (i=1; i < repeatval; i++) {
> {
>
> I have tried assigning the repeatval field in javascript with repeatval =
> document.form.value this works, but the for loop errors out.
>
> Any ideas.
>
> Thanks
>
> Gary




More information about the thelist mailing list