开发者

Struts Disabled field

开发者 https://www.devze.com 2023-02-04 16:04 出处:网络
I need to disable a dropdown on jsp page when it loads.However the html element will not be posted if it is disabled.I tried using a hidden element with the same i开发者_开发问答d as the html element

I need to disable a dropdown on jsp page when it loads.However the html element will not be posted if it is disabled.I tried using a hidden element with the same i开发者_开发问答d as the html element it still does not post the element.I am using struts.Any advice would be appreciated.

Thanks Minu


Your approach was good but you didn't use the proper attribute. The name is sent on the request not the id attribute.

Here is a simple example on how to do it (save this in a file named t.html):

<script type="text/javascript">
    function disableCombo() {
        var combo = document.getElementById("comboId");
        var txt = document.getElementById("txtId");
        combo.disabled = true;
        txt.value = combo.value;
    }
</script>

and then...

<body onload="javascript:disableCombo();">
    <form method="get" action="t.html">
        <select name="comboName" id="comboId">
            <option value="v1">Value 1</option>
            <option value="v2" selected="selected">Value 2</option>
            <option value="v3">Value 3</option>
        </select>
        <input type="hidden" name="comboName" id="txtId" value="waiting to see what happens" />
        <input type="submit" value="watch the address bar" />
    </form>
</body>

When you press submit, the value of the combo (already copied in the hidden field when you disabled the combo on load) is sent on the request.

0

精彩评论

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