Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make an input field read only but still have it send data back to a form?

Tags:

html

css

I have an input field:

<input cid="Topic_Created" name="Topic.Created" size="25" type="text" value="6/5/2011 8:22:45 AM" /> 

I want the field to display on my form but don't want the user to be able to edit the field. When the user clicks submit I want the form value to be sent back to the server.

Is this possible. I tried different combinations of disabled = "disabled", readonly = "readonly". Seems I always get nothing sent back for the field.

like image 843
UCC Avatar asked Jun 05 '11 09:06

UCC


People also ask

How do I make input fields read only?

The readonly attribute of <input> element in HTML is used to specify that the input field is read-only.

Does readonly input get submitted?

A readonly element is just not editable, but gets sent when the according form submits. A disabled element isn't editable and isn't sent on submit.

How do I make a form field not editable?

The readonly attribute makes a form control non-editable (or “read only”). A read-only field can't be modified, but, unlike disabled , you can tab into it, highlight it, and copy its contents. Setting the value to null does not remove the effects of the attribute. Instead use removeAttribute('readonly') .

Is it possible to make input fields read only through CSS?

Pure CSS Form Read-Only Inputs Class: There is no class for that we have a predefined attribute that can make any input field read-only and that attribute is readonly=” ” with empty value.


1 Answers

Adding a hidden field with the same name will sends the data when the form is submitted.

<input type="hidden" name="my_name" value="blablabla" /> <input type="text" name="my_name" value="blablabla" disabled="disabled" /> 
like image 106
Petah Avatar answered Oct 01 '22 12:10

Petah