aspose file tools*
The moose likes Struts and the fly likes generate id attribute of <p> tag dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "generate id attribute of <p> tag dynamically " Watch "generate id attribute of <p> tag dynamically " New topic
Author

generate id attribute of <p> tag dynamically

vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
how to generate id attribute of

tag dynamically by appending a javascript variable.

i tried the below code. but it does not work.



please help me. thank you.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

Please take the time to choose the correct forum for your posts. This forum is for questions on JSP. For more information, please read this.

This post has been moved to a more appropriate forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Srikkanth Mohanasundaram
Ranch Hand

Joined: Feb 07, 2007
Posts: 185
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.

Thanks,
Srikkanth
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

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
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
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.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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
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: 15376
    
    6
As Bear has already stated, JavaScript has nothing to do with your iterator. The incrementing ids should be calculated with your Java code.

Eric
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm actually going to move this to the Struts forum, as it's Struts-specific as described.

This has nothing to do with JavaScript--why do you want to use JavaScript to do something that's already provided for you?http://struts.apache.org/2.1.8/docs/iterator.html
vikas sharmaa
Ranch Hand

Joined: Jun 28, 2007
Posts: 191
awesome newton!!! thank you very much for making things simple.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: generate id attribute of <p> tag dynamically