0

I have a form and it has several fields. There is an ID field which is generated from another form. Now i want to prevent users to change that field value.

How do i do this? DO i need any javascript or anything else?

Roman C
  • 49,761
  • 33
  • 66
  • 176
adarksun
  • 371
  • 1
  • 6
  • 20
  • 2
    Google would have been a lot faster ya know – Sterling Archer Sep 27 '13 at 16:00
  • 2
    And would've brought you [here](http://stackoverflow.com/questions/372604/html-input-box-disable) :) – Justin K Sep 27 '13 at 16:01
  • @adarksun well on a serious note, You should show some efforts before asking question as it is harmful for SO(some say but i think GC of SO is quite well) and for yourself too, I already flagged it (no downvote though) and i suggest you to be more proactive. – Suraj Singh Sep 27 '13 at 16:12
  • http://kreotekdev.wordpress.com/2007/11/08/disabled-vs-readonly-form-fields/ – Suraj Singh Sep 27 '13 at 16:13

5 Answers5

4

You can use disabled on the field:

<input type='text' disabled />

Or readonly

<input type='text' readonly />
tymeJV
  • 103,943
  • 14
  • 161
  • 157
1
<input type="text" name="NAME-OF-FIELD" value="VALUE-NOT-TO-CHANE" disabled="disabled" />

or you could use

<input type="text" name="NAME-OF-FIELD" value="VALUE-NOT-TO-CHANE" readonly />

or if you need to hide it

< input type="hidden" name="NAME-OF-FIELD" value="VALUE-NOT-TO-CHANE" />

You will still have access to it when you submit the form.

lasbreyn
  • 141
  • 1
  • 4
0

If you can change the HTML, I'd suggest making the input hidden with type="hidden".

If you can't, apply the CSS style display:hidden to it.

Or did you want to leave it visible?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
0

You have to disable the field:

<input type="text" disabled="disabled" />

Or set it readonly

<input type="text" readonly="readonly" />
Flea777
  • 1,012
  • 9
  • 21
0

A readonly element not editable, but gets sent when the form submits. a disabled element isn't editable and isn't sent on submit.Readonly elements can be focused while disabled elements can't.

<input type="text" readonly />
Suraj Singh
  • 4,041
  • 1
  • 21
  • 36