Radio button com request.getParameter()

5 respostas
JJjava

olá,
estou tendo um problema com radio button. fiz um jsp de pesquisa e dentro desse jsp tem o form abaixo:

</p>
        <p align="center"><span class="style7">Ticket de helpdesk</span></p>
        <p align="left" class="style2"><span class="style5">
        <%out.println(" "+welcome);%></span></p>
        <form name="form1" method="post" action="result.jsp">
          <table width="701" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="71" class="style12">Pesquisa:</td>
        <td width="630"><label>
                <input name="pesquisa" type="text" id="pesquisa"  size="70">
              </label></td>
            </tr>
          </table>
          <table width="701" height="36" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="23" class="style13">ID:</td>
<td width="29" class="style8"><span class="style11">
  <label>
                <input name="radio" type="radio" value="id" checked>
        </label>
</span></td>
              <td width="53" class="style13">Status:</td>
<td width="29" class="style8"><span class="style11">
  <label>
                <input type="radio" name="radio"  value="status">
        </label>
</span></td>
              <td width="44" class="style13">Login:</td>
<td width="29" class="style8"><span class="style11">
  <label>
                <input type="radio" name="radio"  value="login">
        </label>
</span></td>
              <td width="40" class="style13">Data:</td>
<td width="209" class="style8"><span class="style11">
  <label>
                <input type="radio" name="radio"  value="data">
        </label>
</span></td>
<td width="245"><label>
                <input type="submit" name="query" id="query" value="Pesquisar">
              </label></td>
            </tr>
          </table>
    </form>
        </body>
</html>

entao quando se submet a pesquisa o post vai para uma pagina result , que tem o mesmo form para que as proximas pesquisas sejam feitas nele mesmo, coloco o valor de pesquisa no campo e queria deixar selecionado o radio button tb, como na pesquisa do google…

id = request.getParameter("radio");
                    

                     if(id == "id")
                     {
                         ch_id ="checked";
                     }
                     if(id == "status")
                     {
                         ch_status ="checked";
                     }
                     if(id == "login")
                     {
                         ch_user ="checked";
                     }
                     if(id == "data")
                     {
                         ch_data ="checked";
                     }
                 }
            }
        %>
        </p>
        <p align="center"><span class="style7">Ticket de helpdesk</span></p>
        <p align="left" class="style2"><span class="style5">
        <%out.println(" "+welcome);%></span></p>
        <form name="form1" method="post" action="result.jsp">
          <table width="701" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="71">Pesquisa:</td>
              <td width="630"><label>
                      <input name="pesquisa" type="text" id="pesquisa" value="<%out.println(request.getParameter("pesquisa"));%>" size="70">
              </label></td>
            </tr>
          </table>
          <table width="701" height="36" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="24">ID:</td>
              <td width="30"><label>
                <input name="radio" type="radio" id="id" value="id" <%out.println(ch_id);%>>
              </label></td>
              <td width="48">Status:</td>
              <td width="30"><label>
                      <input type="radio" name="radio" id="status" value="status"  <%out.println(ch_status);%>>
              </label></td>
              <td width="44">Login:</td>
              <td width="30"><label>
                <input type="radio" name="radio" id="login" value="login"  <%out.println(ch_user);%>>
              </label></td>
              <td width="41">Data:</td>
              <td width="201"><label>
                <input type="radio" name="radio" id="data" value="data" <%out.println(ch_data);%>>
              </label></td>
              <td width="253"><label>
                <input type="submit" name="query" id="query" value="Pesquisar">
              </label></td>
            </tr>
          </table>
          </form>
        </body>
</html>

grato.

5 Respostas

rogelgarcia
ch_data ="checked=\"checked\"";

Tenta assim (troque em todos os ifs)

rogelgarcia

troque

id == "data"

por

id.equals("data")
JJjava

[quote=rogelgarcia]troque

id == "data"

por

id.equals("data")

eu estava a função equals mas nso sei pq nao funciona e tb nao esta funcinadno id == “data” nao entra no if entao mudei osvalores do radio button para inteiro e agora esta entrando no if…

rogelgarcia

Mas o “checked=“checked”” funcionou?

JJjava

funcionou sim!!! wlw

Criado 28 de fevereiro de 2010
Ultima resposta 2 de mar. de 2010
Respostas 5
Participantes 2