Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on making a dropdown list read-only

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there not a way to set a DROPDOWN list to READONLY using jQuery or straight javascript? The objective is to NOT let a user change the value selected in the dropdown list.

I am able to set a dropdown list to DISABLE using jQuery but I cannot seem to make it readonly. Please see the code line in RED below.

I'm sure I'm doing something wrong I just don't know what it is. Any help/direction would be appreciated. Thanks.

Here is the jQuery code:

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you cannot change a select list so that the value cannot be changed. What you could do is bind to the change event, and when it is changed, change it back to whatever you want. You could possibly get extra fancy and position a transparent div over the top of it (would have to use an iframe hack for IE) but that seems like a lot of work for little gain.

Final advice is if you have a select list that shouldn't be changed, don't show a select list.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick reply.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic