Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Using ID of link as Parameter

 
Ranch Hand
Posts: 2131
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: 67618
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: 2131
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: 67618
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: 2131
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic