Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Get the form value

Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In my application i need to pass some of my form values with the html:link,i mean i will select a value from my combobox i need to pass that value also with the html:link .How can i do that?

Thanks in Advance
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you want to change the value of a link based on what the user selects before clicking on the link, you must do this on the client side, not the server side, which means you must use javaScript.

The first thing you need to do is specify styleId="xxx" in your <html:link> tag where xxx is some unique identifier. This will make it easier to access the tag in javaScript.

You will next need to retrieve the href property of this object and change it according to your needs. The best place to do this would be in the onchange event of the combo box.

Supposing you wanted to append the value of the combo box as a parameter to the URL of the link, here's some sample code:

function changeHref(optionValue) {
var link = document.getElementById('myLink');
link.href = link.href + '?option=' + optionValue;

<html:link styleId="myLink" action="/myAction" />
<html:select property="mySelect" onchange="changeHref(this.value);">

This is a bit simplified. In the real function, you'd want to insert code to remove the ?option parameter from the href string before adding it. This would allow for the case of the user selecting first one option, then changing her mind and selecting another.
[ January 31, 2006: Message edited by: Merrill Higginson ]
He does not suffer fools gladly. But this tiny ad does:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic