Home HTML form readonly SELECT tag/input
Reply: 0

HTML form readonly SELECT tag/input

user11205
1#
user11205 Published in September 19, 2018, 6:43 pm

According to HTML specs, the select tag in HTML doesn't have a readonly attribute, only a disabled attribute. So if you want to keep the user from changing the dropdown, you have to use disabled.

The only problem is that disabled HTML form inputs don't get included in the POST / GET data.

What's the best way to emulate the readonly attribute for a select tag, and still get the POST data?

share|improve this question
  • 4
    Don't rely on that for the server side. Anybody can create their own HTML page and make it RW. – Brendan Byrd Nov 6 '12 at 19:43
  • 11
    But it's not a PHP-specific question. – Kaleb Brasee Oct 3 '13 at 23:03
  • 3
    I would suggest not using a select element at all in this case. Is there any reason you can't just display the value as plain text? – David Kennedy Sep 4 '14 at 21:59
  • 2
    @ppumkin your comment makes no sense. I'm not saying there's never a good use case for select or hidden form fields. The OP was having trouble displaying some text on the page, and I was simply wondering what the purpose was of using a select element in this case. – David Kennedy Nov 25 '14 at 18:16
  • 2
    I must be reading the wrong question. He says he wants to disable the select so the user doesn't change it. Maybe he needs to render the page with selects and use jquery to prevent changes. But when he submits it back there is no data for it. I was doing the same. I need to display selects that is filtered by other selects and the last drop down saves to DB via ajax so all the previous must be locked down. When I re render the page, yea, OK- I could display labels instead of selects. But that is not the problem :) – ppumkin Nov 25 '14 at 19:04

37 Answers 37

active oldest votes
1 2 next
up vote 381 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.439524 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO