Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

Try This One

   $('#dropdownA').attr("disabled", true);

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)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top