Cannot access the value of the selected item of a

2019-06-03 12:44发布

问题:

On a Jsp page I have some select elements which were disabled after a value was selected (Disabled them in javascript). Now when the form is submitted, I can not access those selected values in the action class.

I know for sure that this is caused by the select elements being disabled because, when I tried the same without making them disabled, it worked fine.

Now I don't understand why is this so. I thought maybe I should enable them before the form is submitted, but it does not seem a good idea.

I faced this problem while implementing this : Creating struts 2 forms dynamically on jsp using java script . (You can find the code there. Although I don't think you will need the code, because it is clear where the problem is.)

Here I am able to access the values of text fields but I can not access the values of select elements.

I asked this question separately because I thought this is a different topic.

Thanks!!

回答1:

You can set them in hidden field through java script and pass it to action



回答2:

Disabled fields by W3 specifications will not get posted on the server side so this issue is not related to the Struts2 but in generic an HTML way to go

Disabled controls

i am not sure why you want to use disabled control for your form.things can be done using readOnly attribute or use hidden fields