//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);
});
//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 );
});
jQuery(document).ready(function($) {
var $dropDown = $('#my-select'),
name = $dropDown.prop('name'),
$form = $dropDown.parent('form');
$dropDown.data('original-name', name); //store the name in the data attribute
$('#toggle').on('click', function(event) {
if ($dropDown.is('.disabled')) {
//enable it
$form.find('input[type="hidden"][name=' + name + ']').remove(); // remove the hidden fields if any
$dropDown.removeClass('disabled') //remove disable class
.prop({
name: name,
disabled: false
}); //restore the name and enable
} else {
//disable it
var $hiddenInput = $('<input/>', {
type: 'hidden',
name: name,
value: $dropDown.val()
});
$form.append($hiddenInput); //append the hidden field with same name and value from the dropdown field
$dropDown.addClass('disabled') //disable class
.prop({
'name': name + "_1",
disabled: true
}); //change name and disbale
}
});
});
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.