1

I'm trying to POST to a JSP page some values with radio buttons.

It's a little paradoxic:

  • By selecting another radio button it doesn't deselect the previous one, if I take various names for the radio buttons, but if I name the radio buttons equal it always returns me the value 'on' by trying to catch the value with -> request.getAttributes('filter').

To getting the value 'on' if one of them is selected is way pointless, if the speech is about radio buttons.

My question now is how will I able to catch which one of them is selected? Maybe by setting the value tag and getting it on the JSP site? If so, how is that achievable?

The worst case is, that I name the radio buttons with various values and deselect the previous one with javascript.

<form method="post" action="./activity.jsp">
    <input type="radio" name="filter" value="nofilter" checked="checked"> Kein Filter
    <input type="radio" name="filter" id="dayRadio"> Tag
    <input type="text" id="day" onfocus="choosed(this)">
    <input type="radio" name="filter" id="weekRadio"> Woche
    <input type="text" id="week" onfocus="choosed(this)">
    <input type="radio" name="filter" id="monthRadio"> Monat
    <input type="text" id="month" onfocus="choosed(this)">
    <input type="radio" name="filter" id="yearRadio"> Jahr
    <input type="text" id="year" onfocus="choosed(this)">
    <input type="submit" value="OK">
</form>
Sercan Savran
  • 103
  • 1
  • 2
  • 7

1 Answers1

0

The idea is that you group the radio buttons together by giving them the same name, but then you assign the different buttons different values, so you know which one has been clicked

<INPUT TYPE="radio" name="filter" value="1"/>Tag
<INPUT TYPE="radio" NAME="filter" VALUE="2"/>Woche

and then in your java

String value= request.getParameter("filter");
System.out.println(value);
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64
  • I don't know, how to mark this as the correct answer. Now I get in the java side the value which I set on the html by using request.getParameter("filter");. Thank you so much! – Sercan Savran Jun 22 '17 at 12:16