I am using the following statement to make it readonly but it is not working.
$(\'#cf_1268591\').attr(\"readonly\", \"readonly\");
I don\
I'd make the field disabled. Then, when the form submits, make it not disabled. In my opinion, this is easier than having to deal with hidden fields.
//disable the field
$("#myFieldID").prop( "disabled", true );
//right before the form submits, we re-enable the fields, to make them submit.
$( "#myFormID" ).submit(function( event ) {
$("#myFieldID").prop( "disabled", false );
});
Maybe you can try this way
function myFunction()
{
$("select[id^=myID]").attr("disabled", true);
var txtSelect = $("select[id^=myID] option[selected]").text();
}
This sets the first value of the drop-down as the default and it seems readonly
html5 supporting :
`
$("#cCity").attr("disabled", "disabled");
$("#cCity").addClass('not-allow');
`
Here is a slight variation on the other answers that suggest using disabled. Since the "disabled" attribute can actually have any value and still disable, you can set it to readonly, like disabled="readonly". This will disable the control as usual, and will also allow you to easily style it differently than regular disabled controls, with CSS like:
select[disabled=readonly] {
.... styles you like for read-only
}
If you want data to be included submit, use hidden fields or enable before submit, as detailed in the other answers.
This code will first store the original selection on each dropdown. Then if the user changes the selection it will reset the dropdown to its original selection.
http://jsfiddle.net/4aHcD/22/
//store the original selection
$("select :selected").each(function(){
$(this).parent().data("default", this);
});
//change the selction back to the original
$("select").change(function(e) {
$($(this).data("default")).prop("selected", true);
});
$('#cf_1268591').attr("disabled", true);
drop down is always read only . what you can do is make it disabled
if you work with a form , the disabled fields does not submit , so use a hidden field to store disabled dropdown value