1

I have a drop down list. And I want that the users cannot change the value of that drop down so for this I used the disabled="disabled" property but now I am unable to get the value from the drop down list.

So what should I do with my situation so that the users could not change the value of it and I can get the value of that drop down list also?

Matt Gibson
  • 14,616
  • 7
  • 47
  • 79
Ahmad
  • 2,099
  • 10
  • 42
  • 79

4 Answers4

1

Sounds like a dropdown isn't what you should be using here.

I'd probably use a hidden input box (for the JS to populate) + just plain text to display to the user.

But I guess it depends on what you're trying to do, so more information would be good.

Nick
  • 6,316
  • 2
  • 29
  • 47
1

You can

  • store the dropdown value in the session
  • add the same value to which the dropdown is set to a hidden input
scibuff
  • 13,377
  • 2
  • 27
  • 30
0

My solution has always been to render the dropdown as some other HTML element and have a hidden input for the actual value. This has the advantage that people know it's not changeable, whereas a disabled field could imply that it can be activated somehow. If you must have it as a dropdown, just change it's name and id so that it doesn't interfere with the hidden field.

Disabled elements are never passed back when the form is submitted so this is the only realistic option without using javascript and that leaves a problem if people have it disabled, so it's best avoided for this.

Matt Gibson
  • 14,616
  • 7
  • 47
  • 79
0

Browsers wont submit disabled fields, you would have to somehow parse them with javascript and submit them seperately

Tarang
  • 75,157
  • 39
  • 215
  • 276