开发者

How to get the value of a disabled text field in jsp

开发者 https://www.devze.com 2023-04-09 19:02 出处:网络
I am having a dropdown box and a 5 textfields( all di开发者_开发技巧sabled). I am entering data into textfield by using javascript, from the dropdown(what ever value is present in the dropdown, goes i

I am having a dropdown box and a 5 textfields( all di开发者_开发技巧sabled). I am entering data into textfield by using javascript, from the dropdown(what ever value is present in the dropdown, goes into the text fields).

Now, when the submit button is clicked, I want to get the value from this text field in the action class(java). On testing, I was getting "null" [getParameterValues("textfieldname") is what I have done].

When I removed the disabled, I was getting the value. So, how can I get the value while the disabled, is applied to the text field ?


Instead of disable them make them readonly.

<input type="text" name="nameOfTextField" readonly="readonly" />


if you want the field to be disabled you can use an hidden input like this:

<input type="text" id="nameVisible" disabled="disabled" />
<input type="hidden" name="nameObj" id="nameObj"/>

when you load page, you set value in both fields via DOM
in this way you'll see the input disabled on the page, and you'll get the hidden value when you submit it.


If you still want text fields to be disabled, double them: one with disabled, other with hidden type.

Example:

<select name="selectedItem">
    <option value="1" selected>A</option>
    <option value="2" selected>B</option>
</select>

<input name="iname" value="${selectedItem}" disabled />
<input name="inameh" value="${selectedItem}" type="hidden" />

Now the iname field will be visible at site (disabled), and you can get the choosen value from inameh (hidden) with:

javascript: getParameterValues("inameh")
java: request.getParameterValues("inameh")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号