This won't work because the javascript executes on your browser . You need to create the ids for your paragraph tags on the server.(meaning this should be done in java)
I'm not sure what this custom tag does , but please take a look at the custom Tag documentation they might have provided a counter for this purpose.
It can certainly be done in JavaScript on the client as part of page initialization, but I'd do it on the server with JSP. Why wait to do it on the client?
Srikkanth Mohanasundaram
Ranch Hand
Joined: Feb 07, 2007
Posts: 185
posted
0
Yup I agree that it can be done on the client side, what i meant was the code which was posted won't work. Thanks for clearing the ambiguity.
By the way you can JSTL core tag forEach for this purpose (I suppose that you are trying to use struts iterator)
Thanks,
Srikkanth
vikas sharmaa
Ranch Hand
Joined: Jun 28, 2007
Posts: 191
posted
0
Srikkanth Mohanasundaram wrote:
I'm not sure what this
this is struts2 iterator tag for looping.
but my query is related to javascript only. in the statement,
i want to assign id as para_1, para_2 etc. in the loop. ctr value is incrementing in the loop.
there must be a way of doing it at client side. if anyone knows then please give me a hint.
vikas sharmaa wrote:there must be a way of doing it at client side. if anyone knows then please give me a hint.
Here's a hint: if you want to write a loop over some list on the client side, then that list has to exist at the client. This list doesn't. So if you insist on not doing it the obvious and natural way, you'll have to figure out some way of getting the list to the client. I don't particularly want to help you do that because I don't think it's a good idea.
vikas sharmaa
Ranch Hand
Joined: Jun 28, 2007
Posts: 191
posted
0
paul,
i am getting the list from the server in the form of mylist.
let me elaborate the problem here:
i have an iterator loop that contains the bunch of fields. these fields are categorised into < p > tags to use in DOM to hide them on selecting a checkbox.
now, i want id attribute of < p > tag to be different in each iteration. for that, i am appending ctr var to the id tag. but it is not working. please help.
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
6
posted
0
As Bear has already stated, JavaScript has nothing to do with your iterator. The incrementing ids should be calculated with your Java code.