Reputation: 5799
I'm working on an ASP.Net app
I have a drop down that, under some conditions, should be 'read only', that is, the user can't change it but, on a post back its selected value can be read.
Now I know that the readOnly attribute is not available for drop downs so I'm trying to build a method that simulates this
so I wanted to make a javascript function that doesnt let the user 'open' the drop down to select an item. is this possible?
here's the example
function MakeDropDownReadOnly(dropDownId, makeReadOnly){
var myDropDown = document.getElementById(dropDownId);
if(makeReadOnly){
//Block drop down
}
else{
//Unblock drop down
}
}
tks
Upvotes: 0
Views: 2932
Reputation: 7600
onfocus="this.blur()"
might work to prevent a user to interact with the select.
Upvotes: 0
Reputation: 66388
Make it disabled then in form submit (using JavaScript) enable it again so the value will be sent to the server.
Sample code to enable upon submitting:
document.getElementById("<%=DropDown1.ClientID%>").disabled = false;
Upvotes: 1