Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 519
  • Last Modified:

Passing form parameter value

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.

2 Solutions
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>
scoobie5Author Commented:
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'
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


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now