How to make a dropdown readonly using jquery?
I am using the following statement to make it readonly but it is not working.
$('#cf_1268591').attr("readonly", "readonly");
I don't want make it disabled, I want to make it readonly.
$('#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
I had the same problem, my solution was to disable all options not selected. Very easy with jQuery:
$('option:not(:selected)').attr('disabled', true);
Edit => If you have multiple dropdowns on same page, disable all not selected options on select-ID as below.
$('#select_field_id option:not(:selected)').attr('disabled', true);
This is what you are looking for:
$('#cf_1268591').attr("style", "pointer-events: none;");
Works like a charm.
Try this one.. without disabling the selected value..
$('#cf_1268591 option:not(:selected)').prop('disabled', true);
It works for me..
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 );
});