Asked  7 Months ago    Answers:  5   Viewed   32 times

I have some disabled inputs in a form and I want to send them to a server, but Chrome excludes them from the request.

Is there any workaround for this without adding a hidden field?

<form action="/Media/Add">
    <input type="hidden" name="Id" value="123" />

    <!-- this does not appear in request -->
    <input type="textbox" name="Percentage" value="100" disabled="disabled" /> 

</form>

 Answers

37

Elements with the disabled attribute are not submitted or you can say their values are not posted (see the second bullet point under Step 3 in the HTML 5 spec for building the form data set).

I.e.,

<input type="textbox" name="Percentage" value="100" disabled="disabled" /> 

FYI, per 17.12.1 in the HTML 4 spec:

  1. Disabled controls do not receive focus.
  2. Disabled controls are skipped in tabbing navigation.
  3. Disabled controls cannot be successfully posted.

You can use readonly attribute in your case, by doing this you will be able to post your field's data.

I.e.,

<input type="textbox" name="Percentage" value="100" readonly="readonly" />

FYI, per 17.12.2 in the HTML 4 spec:

  1. Read-only elements receive focus but cannot be modified by the user.
  2. Read-only elements are included in tabbing navigation.
  3. Read-only elements are successfully posted.
Tuesday, June 1, 2021
 
aWebDeveloper
answered 7 Months ago
13

Maybe you want to write name = "nv_select". You forget equal. Of course name atributes should be different nv_select1, nv_select2 etc.

Friday, May 28, 2021
 
GGio
answered 7 Months ago
29

Try this using javascript. It worked for me:

 <form name='searchdata' id="search_form" action="search.php" method="get">
                <div class="input-with-icon success-control">  
                    <input type="text" class="form-control" id="form1Amount"     name="searchvalue" placeholder="Search in users or #hashtags"><br/>
                </div>  
                <button onclick="form_submit()" name='user_search' value='user' class="btn btn-danger"><i class="fa fa-user"></i> User</button>
                <button onclick="form_submit()" name='tag_search' value='tag' class="btn btn-default"><i class="fa fa-tag"></i> Tags</button>           
        </form> 

  <script type="text/javascript">
  function form_submit() {
    document.getElementById("search_form").submit();
   }    
  </script>
Monday, September 20, 2021
 
Mild Fuzz
answered 3 Months ago
43

There's apparently a bug in the way Firefox and Chrome handle padding in table cells in HTML5: http://code.google.com/p/chromium/issues/detail?id=50633

When you try your markup and CSS with 0 padding, they're the same. When you switch the DOCTYPE to be not HTML5 they are the same as well.

Thursday, October 7, 2021
 
Mahmoud Saleh
answered 2 Months ago
87

This is by design, disabled elements do not get submitted with the form.

What you are doing is actually a null practice, no matter what you do to that form in put it will be editable by the end user. You simply cannot trust form input - even hidden fields - to not be tampered with.

Your best bet is to just display the information to the user and load it again after the form has been submitted; at worst store it in a session.

Sunday, October 10, 2021
 
Bohemian
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share