0

Good day all,

I tried to disable a drop down list by jQuery, and I would like to maintain the value in the drop down list in server side/ back-end although it has been disable.

This is my jQuery code:

if('${actionBean.list1.size()}' > 0)
    $('#dropdownA').prop("disabled", true);

However, after I disable the drop down, the value become null in my java file :

System.out.println("dropdown value is " + getdropdownA());

Any idea to maintain the value although I disable the drop down list after user selected on it?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Panadol Chong
  • 1,793
  • 13
  • 54
  • 119
  • 3
    possible duplicate of [Readonly SELECT tag](http://stackoverflow.com/questions/368813/readonly-select-tag) – Moshe Katz Jan 07 '14 at 06:23

3 Answers3

1

Disabled elements do not get submitted with forms (hence the null value), so the easiest way to get around this would be to use a hidden element.

Something like:

if('${actionBean.list1.size()}' > 0){
  var dropDown = $('#dropdownA');
  $("myHiddenElement").val(dropDown.val());
  dropDown.prop("disabled", true);
}

Then you can check if dropDown has a value on the server and if not, default to myHiddenElement.

James Hibbard
  • 16,490
  • 14
  • 62
  • 74
0

Try This One

   $('#dropdownA').attr("disabled", true);
Dinesh
  • 1,005
  • 5
  • 16
  • 38
0

try using this to make the dropdown displayed as if it is 'disabled'

$(#dropdownA).css({"background-color":"rgb(238, 238, 238)", "pointer-events":"none"}).keydown(false)
mch
  • 3
  • 2
mch
  • 1