• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Using ID of link as Parameter

 
Ranch Hand
Posts: 2247
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using JSTL to populate an HTML table. On of the columns is a link to print an associated selected document. I an using the document index as the id of each link as the table is created. my href is javascript:viewprint() how can I use the id such as javascript:viewprint(this.id)?
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're not giving us much to go on.

In a Javascript function you can grab the ID of the event target, or, since you are creating the JavaScript in a JSP to being with, simply include the id in the JavaScript to begin with and not have to look it up at execution time.
 
Steve Dyke
Ranch Hand
Posts: 2247
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once again I really don't understand the suggestion. I will try and explain my situation with more clarity. Sorry for the first post not explaining very well.

In my jsp I use JSTL to populate a table with four columns. Column one is the document index which appears as a button with the value set to the index number, so authorized users can click and edit the document. The second column has part number, third is description. For the fourth column I want to put a link in each row appearing as view/print. When the user clicks this link the document will open as a printable document.

So when the JSTL runs on the page load I check the column number. If it equals 3 I put:
id="${itemArrayList}" href="javascript:viewprint(this.id)"

My function is(for test)

function viewprint(wValue)
alert(wValue)

Now after the page loads and I click on one of the links I get undefined.

I hope this makes sense.
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the easiest thing to do would be:
<blockquote>code:
<pre name="code" class="core">id="${itemArrayList}" href="javascript:viewprint('${itemArrayList}')" </pre>
</blockquote>
 
Steve Dyke
Ranch Hand
Posts: 2247
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear.

I tried that earlier but had parameter surrounded by double quotes. After you suggestion found that no quotes are required.
 
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic