Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

access var name 1

Status
Not open for further replies.

onressy

Programmer
Mar 7, 2006
421
CA
Hi i'm using asp to write out some javascript variables like so:
<script>
var wsb0="peach"
var wsb1="plum"
var wsb2="pear"
var wsb3="apple"
var wsb4="orange"
var wsb5="banana"
var wsb6="pineapple"
</script>

I would like to use document.write the values of each variable name in an list, like so:

peach
plum
pear
apple
orange
banana
pineapple

Now in the situation above i have var wsb0 to wsb6, this is not walways the case as sometimes i have upto wsb20 and sometime only 4 of them.

Not sure how to go about this, Thanks
 
Use the window collection to access the variables, and you can run them thru a loop provided you know the maximum amount:
Code:
<script type="text/javascript">

var wsb0="peach";
var wsb1="plum";
var wsb2="pear";
var wsb3="apple";
var wsb4="orange";
var wsb5="banana";
var wsb6="pineapple";

for (i = 0; i < 7; i++) {
   document.write(window["wsb" + i] + "<br />");
}

</script>

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
ggriffit does have a point though, you might as well just stick them in an array if you're pulling them in statically like that.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top