www.webdeveloper.com
Results 1 to 4 of 4

Thread: strange behavior with disabled select box

  1. #1
    Join Date
    Jun 2004
    Posts
    1,299

    strange behavior with disabled select box

    Hi,

    Is it normal for a disabled select box to not pass its value through to $_POST?

    I have two selects on my page.

    The first select box if a certain value is selected it sets the value of selectbox2 and disables it but that selectbox2 then has no data when I check the $_post array when I want it to pass the data I just set it too?

    Any ideas, or is there a better way of doing?

    Thanks
    k0r54

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,926
    Quote Originally Posted by k0r54 View Post
    Hi,

    Is it normal for a disabled select box to not pass its value through to $_POST?

    I have two selects on my page.

    The first select box if a certain value is selected it sets the value of selectbox2 and disables it but that selectbox2 then has no data when I check the $_post array when I want it to pass the data I just set it too?

    Any ideas, or is there a better way of doing?

    Thanks
    k0r54
    It is not only normal, is what the w3c specification says it should do. You can set it to "readonly" instead. (You may have to do a little CSS fiddling if you want it to look the same as disabled.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Nov 2008
    Posts
    2,477
    I tend to add a hidden field with a value of 0 just before the checkbox (and named the same as the checkbox) when I want a value even if the checkbox is empty or disabled:

    HTML Code:
    <input type="hidden" value="0" name="foo" />
    <input type="checkbox" value="1" name="foo" />

  4. #4
    Join Date
    Jun 2004
    Posts
    1,299
    Hi,

    Thanks for the input, I did notice that select does not actually have a readonly so to get around it I put it all into a span and i get the JS to hide the div but leave the select box enabled with the value i tell it.

    Thanks
    k0r54

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles