not checked checkboxes input are not sent by the browser

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lehmann

    not checked checkboxes input are not sent by the browser

    Hello,

    I discovered that in a form with checkboxes input, if the checkboxe is
    not checked, not value is sent in my request by the browser (at least
    IE, I think it is ok in NS).
    But I my application I need to get the input even if it is not checked
    (my form is dynamic and I distinguish the cases: input exists and is
    cheched / input exists ans is not checked / input doesn't exists)
    I know I could use another input such as textfield, but I wonder if
    there is another solution that would allow me to keep the checkboxe
    and send it even if not checked.
    Thanks for any help!
    G.
  • David Dorward

    #2
    Re: not checked checkboxes input are not sent by the browser

    lehmann wrote:
    [color=blue]
    > Hello,
    >
    > I discovered that in a form with checkboxes input, if the checkboxe is
    > not checked, not value is sent in my request by the browser (at least
    > IE, I think it is ok in NS).[/color]

    Its "OK" in all browsers.

    Unchecked checkboxes are not submitted, that is how it is supposed to work.
    [color=blue]
    > But I my application I need to get the input even if it is not checked[/color]

    Then test for the _existance_ of the variable rather then its value.
    [color=blue]
    > (my form is dynamic and I distinguish the cases: input exists and is
    > cheched / input exists ans is not checked / input doesn't exists)[/color]

    Then you should include an input that specifies which checkboxes exist.

    --
    David Dorward http://david.us-lot.org/
    Redesign in progress: http://stone.thecoreworlds.net/
    Microsoft announces IE is dead (so upgrade):

    Comment

    • Daniel

      #3
      Re: not checked checkboxes input are not sent by the browser

      > But I my application I need to get the input even if it is not checked[color=blue]
      > (my form is dynamic and I distinguish the cases: input exists and is
      > cheched / input exists ans is not checked / input doesn't exists)
      > I know I could use another input such as textfield, but I wonder if
      > there is another solution that would allow me to keep the checkboxe
      > and send it even if not checked.[/color]

      You say it's dynamic, so just in case it's anything like mine - I'm doing
      something with PHP & MySQL, this is what I did. I put a hidden field in the
      form and link it to the checkbox, like this (a checkbox to click whether or
      not a user's address should be visible on my site):

      <input name="showaddre ssControl" type="checkbox" id="showaddress Control"
      value="showaddr essControl" onClick="this.f orm.showaddress .value =
      ((this.checked) ?1:0)">
      <input name="showaddre ss" type="hidden" value=""
      onChange="this. form.showaddres sControl.checke d =
      ((this.value==1 )?true:false)">

      The first input is the checkbox, and when it's clicked, it sets the hidden
      value to 1 (MySQL for TRUE) if the checkbox is checked, and 0 (FALSE) if
      it's not.

      The second input is the actual value that I get and put from/to the
      database. The reason I have an onchange handler in it is that I dynamically
      fill it with data on different persons, so whenever its value changes, the
      checkbox is changed too to reflect the new value. You could give it a
      default value of "null" or "not set" or something to show when 'input
      doesn't exist').

      Hope this has something to do with what you're doing and that it will help
      ;)

      Cheers,
      Daniel


      --
      There are 10 kinds of people: Those who know binary and those who don't.


      Comment

      • lehmann G.

        #4
        Re: not checked checkboxes input are not sent by the browser



        Your solution seems perfect for me!
        Thanks a lot!!! :-)
        G

        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        Working...