How can I "submit" a "disabled" input?

Discussion in 'HTML' started by Martin, Aug 31, 2004.

  1. Martin

    Martin Guest

    I have a form with several text boxes (<INPUT type="text">) and a
    "submit" button. I would like to display one of the text boxes as
    "disabled" (dimmed but readable) and yet have that text box submitted
    back to the server when the submit button is clicked. How can I make
    this happen?

    I've tried setting type="hidden" but that didn't get submitted.

    I've tried type="text" style="display:none" but that didn't submit
    either.

    I've tried type="text" disabled="disabled". This gives the appearance
    I want but it doesn't get submitted either.

    I've tried type="text" readonly="true". That gets submitted but I
    don't like the display (it's not obvious that it's read-only).
     
    Martin, Aug 31, 2004
    #1
    1. Advertising

  2. Martin wrote:
    > I have a form with several text boxes (<INPUT type="text">) and a
    > "submit" button. I would like to display one of the text boxes as
    > "disabled" (dimmed but readable) and yet have that text box submitted
    > back to the server when the submit button is clicked. How can I make
    > this happen?
    >
    > I've tried setting type="hidden" but that didn't get submitted.


    It should.

    > I've tried type="text" style="display:none" but that didn't submit
    > either.


    It should.

    > I've tried type="text" disabled="disabled". This gives the appearance
    > I want but it doesn't get submitted either.


    It should.

    > I've tried type="text" readonly="true". That gets submitted but I
    > don't like the display (it's not obvious that it's read-only).


    It should.

    Are you sure the form is set up properly? Maybe you forgot to give the
    fields a name?
     
    Leif K-Brooks, Aug 31, 2004
    #2
    1. Advertising

  3. Martin

    Martin Guest

    On Mon, 30 Aug 2004 22:36:55 -0400, Leif K-Brooks
    <> wrote:

    >Martin wrote:
    >> I have a form with several text boxes (<INPUT type="text">) and a
    >> "submit" button. I would like to display one of the text boxes as
    >> "disabled" (dimmed but readable) and yet have that text box submitted
    >> back to the server when the submit button is clicked. How can I make
    >> this happen?
    >>

    OK, I found the errors...

    >> I've tried setting type="hidden" but that didn't get submitted.

    >
    >It should.

    this gets submitted now.


    >> I've tried type="text" style="display:none" but that didn't submit
    >> either.

    >
    >It should.

    this gets submitted now.


    >> I've tried type="text" disabled="disabled". This gives the appearance
    >> I want but it doesn't get submitted either.

    >
    >It should.

    this still does NOT get submitted (and this is the one I want to use).

    >
    >> I've tried type="text" readonly="true". That gets submitted but I
    >> don't like the display (it's not obvious that it's read-only).

    >
    >It should.

    this gets submitted now.

    >
    >Are you sure the form is set up properly? Maybe you forgot to give the
    >fields a name?
     
    Martin, Aug 31, 2004
    #3
  4. Martin

    rf Guest

    Martin wrote:

    > >> I've tried type="text" disabled="disabled". This gives the appearance
    > >> I want but it doesn't get submitted either.

    > >
    > >It should.


    No it shouldn't.

    > this still does NOT get submitted (and this is the one I want to use).


    Read this:
    http://www.w3.org/TR/html4/interact/forms.html#h-17.12

    "Disabled controls cannot be successful", that is, thay cannot be submitted
    with the form.

    Just below this:

    "In this example the INPUT element is disabled. Therefore, it cannot receive
    user input nor will its value be submitted with the form."

    You *could* make the element read only. Read only elements "may be
    successful".

    However, since a disabled (or read only) element cannot be changed by the
    user then whatever you send down to the client would (if the control *could*
    be sucessful) be send back unchanged to the server. You already know what
    you would have got back.

    --
    Cheers
    Richard.
     
    rf, Aug 31, 2004
    #4
  5. Martin

    Augustus Guest

    "Martin" <> wrote in message
    news:...
    > On Mon, 30 Aug 2004 22:36:55 -0400, Leif K-Brooks
    > <> wrote:
    >
    > >> I've tried type="text" disabled="disabled". This gives the appearance
    > >> I want but it doesn't get submitted either.

    > >
    > >It should.

    > this still does NOT get submitted (and this is the one I want to use).


    Disabled elements do not get submitted with the form... that is the way they
    operate.

    You could do up a workaround using hidden form elements along the lines of:

    Your Name: <input type='text' value='Bob' disabled><input type='hidden'
    name='YourName' value='Bob'>

    > >
    > >> I've tried type="text" readonly="true". That gets submitted but I
    > >> don't like the display (it's not obvious that it's read-only).

    > >

    > this gets submitted now.


    You could use this option and then using CSS change its appearance so it
    looks like a disabled form item (I can't remember if the only difference
    between disabled and enabled is the text color becomes #c0c0c0 (silver) on a
    disabled element or if the background color changes as well)
     
    Augustus, Aug 31, 2004
    #5
  6. Martin

    Martin Guest

    What I ended up doing is using both a disabled element AND a hidden
    element. The disabled element is visible to the user but does not get
    submitted; the hidden element (containg the same value) cannot be seen
    by the user but does get submitted for processing. The best of both
    worlds!

    Thanks for the guidance.
     
    Martin, Aug 31, 2004
    #6
  7. Martin

    aeskreis

    Joined:
    Oct 19, 2010
    Messages:
    1
    Sorry to bring this post back from the dead, but I ran into this issue as well and stumbled on this post. I found the hidden fields option to be way too annoying, especially since the textfields coudl possibly need to have user input. My solution was to use the readonly attribute, but to maek it look more "disabled", i set the text color to "#777", which gives it that "disabled" look. If you wanted to go a step further and make the text not even able to be highlighted, you could use the jquery plugin "Disable Text Select" (I would link it but im not allowed, just google it) to disable text highlighting. Hope this helps someone in the future
     
    aeskreis, Oct 19, 2010
    #7
  8. Martin

    maunakea

    Joined:
    May 16, 2012
    Messages:
    1
    <input id="myinput" type="text" readonly style="color:#AAAAAA">
    will be the answer...
    readonly disable all changes - CSS/style change the look...

    Jquery trick will be
    $('#myinput').prop('readonly',true);
    $('#myinput').css("color","#AAAAAA");
     
    maunakea, May 16, 2012
    #8
  9. Martin

    JTaylor

    Joined:
    Feb 2, 2013
    Messages:
    1
    The solution here is fairly simple. Disabled elements are not submitted - so just don't keep them disabled when you are going to submit!

    During the OnSubmit event (or in a javascript attached to your submit button, etc) - just enable those disabled elements! To keep it real simple just enable all of them on the form.

    To prevent input mistakes, you might first hide the entire visible form, or the elements on it just to make sure the user cannot change something in the second or two that the elements become editable before the page refreshes. Set css display:none or visibility:hidden.

    Here is an example function you might call in your onsubmit event. It takes a referrence to the form and enables all the fields so they will get submitted...

     
    Last edited: Feb 2, 2013
    JTaylor, Feb 2, 2013
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guy
    Replies:
    5
    Views:
    2,875
    brucie
    Dec 13, 2003
  2. SirG
    Replies:
    5
    Views:
    447
    Jonathan N. Little
    Nov 15, 2007
  3. JSjones
    Replies:
    4
    Views:
    297
    Thomas 'PointedEars' Lahn
    Feb 12, 2004
  4. Ittay Dror

    how to submit "disabled" form elements

    Ittay Dror, Apr 19, 2004, in forum: Javascript
    Replies:
    0
    Views:
    131
    Ittay Dror
    Apr 19, 2004
  5. Frank Way
    Replies:
    3
    Views:
    154
    Frank Way
    Jan 29, 2005
Loading...

Share This Page