Results 1 to 2 of 2

Thread: Changing value of checkbox depending of data

  1. #1
    Join Date
    Oct 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Changing value of checkbox depending of data

    I have the following code, but it is not working as desired.

    I want that depending of the value carrera.getAbierto() (returns true or false), checkbox with name "abierto" is checked or unchecked.

    What's wrong in this code? I always have the checkbox checked even though abierto="OFF".
    I also tried with property "VALUE". In that case, checkbox was always unchecked.

    <BODY>
    <font size="2">
    <P>
    <H2>Modificacion de Carreras</H2><BR>
    </P>
    <HR>
    <CENTER>
    <FORM NAME='Reg' OnSubmit="return comprobar(Reg);"
    ACTION="<%=path%>/modificaCarrera.action"
    METHOD='POST' target="derecha">
    <INPUT TYPE='hidden' NAME='method' VALUE="ConfirmaModificacion">

    <TABLE>
    <%
    Carrera carrera = (Carrera) request.getAttribute("carrera");
    String abierto = "";
    if (carrera.getAbierto() == true){
    abierto = "ON";
    System.out.println("abierto=SI");
    }
    else{
    abierto = "OFF";
    System.out.println("abierto=NO");
    }

    %>
    <TR>
    <TD><B>Nombre: </B></TD>
    <TD><INPUT TYPE='text' NAME="descripcion" MAXLENGTH=50 SIZE=50
    VALUE="<%= carrera.getDescripcion()%>">
    <INPUT TYPE="Hidden" NAME="id" VALUE="<%= carrera.getId()%>" >
    </TD>
    </TR>
    <TR>
    <TD><B>Abierto:</B></TD>
    <TD><INPUT TYPE='checkbox' NAME="abierto" VALUE="<%= abierto %>"></TD>
    </TR>
    <TR>
    <TD COLSPAN=2>
    <INPUT TYPE='submit' VALUE='Modificar'>&nbsp;<INPUT TYPE='reset' VALUE='Limpiar'>
    </TD>
    </TR>
    </TABLE>
    </CENTER>
    </FORM>
    </font>
    </BODY>

    Any help is appreciated,

    Mónica

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Checkbox doesn't use value.

    It uses "checked"--
    <input type="checkbox" checked>

    I believe selected may work as well.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •