Passing form parameter value

Posted on 2005-03-07
Medium Priority
Last Modified: 2008-02-01
let's say I have  a form which contains a checkbox (which initially is checked and its value is retrieved from a bean) and a link to the next page.  for example

<form name="myForm" method="post" action="/MyProject/MyController">
<input type="checkbox" name="myCheckbox" <%=myBean.getIfCheckedOrNot()%>>

<!-- notice that the checkbox is set to 'checked' initially -->
<a href="someOtherTartget" > Click to Relocate </a>
<input type="submit" value="submit" onclick='test(this.form)';>

If I click on 'Click to Relocate' link....which will take me to some controller....how can I pass the value of the checkbox (checked or not checked) to that class?  Please note, i'm not using the submit button, (that would be easy since i would be using the form elements and i could just do: request.getParameter("myCheckbox")  ) instead i'm clicking on the link....so my initial approach was to use queryString and append the value of the checkbox to the end of the url.  but the value of the checkbox is dynamic (user can check it or uncheck it in the current screen)...so queryString will not work...
That is why I leaning towards the idea that a handy javascript might do the trick.  Does anybody have any idea about how i could resolve this? possibly 'onClick' event....or preferrably a solution that does not involve javascript...

The main idea is that I have to use a link to jump to the next page....and not a submit button....and i need to pass the current value of the checkbox.

Question by:scoobie5
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 32

Accepted Solution

ldbkutty earned 1600 total points
ID: 13481270
Only the "checked" checkboxes will be submitted page. If it is not checked, it will not be sent.

For submitting a page with hyperlink, use this :

<a href="javascript: document.myForm.submit();"> Click to Relocate </a>

Author Comment

ID: 13481368
Thanks...i see what you mean, if the checkbox is not checked then its value is null....so once i click the link and attempt to retrieve the value of myCheckbox using request.getParameter("myCheckbox") in the target controller, the result will be 'null'
LVL 29

Assisted Solution

bloodredsun earned 400 total points
ID: 13481517
You'll have to do a null check in the action that your controller passes onto (I presume that you are using an MVC architecture similar to Struts). The easiest way to do it is check for null and assign checked or unchecked on that value of the bean that maps to the form.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
Hey fellow admins! This time, I have a little fairy tale for you. As many tales do, it starts boring and then gets pretty gory. I hope you like it. TL;DR: It is about an important security matter, you should read it if you run or administer Windows …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question