Hidden DOM element containing the message and to make it visible

与世无争的帅哥 提交于 2019-12-25 08:19:08

问题


I need to show message "Please wait Processing" on click of Submit button using a hidden DOM element which contains the message and make it visible, but the message is not showing.

My html for the form and my validate function are given below.

<form name="siteSearchForm" method=post action="<%=request.getContextPath()%>/servlet/visibilityController" onsubmit="javascript:return validate();on_load()">
    <td align="center" width="10%"><input type=submit name="siteSearchSubmit" value="SUBMIT" >&nbsp;<input type="RESET" name="clearTN" value="RESET"></td>
</form>

I tried the below code by calling on_load on form tag during onsubmit but it is not showing message

<head>
    <script type="text/javascript">
        function on_load(){
            var y = document.getElementById("txtHiddenUname");
            y.type= "text";
        }
    </script>
</head>

<body>
    <input type="hidden" id="txtHiddenUname" value="invalid input" />
</body>

回答1:


Becuase the return statement will exit the function call and nothing after it will run. You would need to add it BEFORE the return.

onsubmit="on_load(); return validate();"

or you can do

onsubmit="return validate() && on_load();"

but your on_load function needs to return true.

function on_load(){  return true; }

Also why are you using an input to display a message? Seems like you should be using a paragraph with display none/block. javascript: is not needed in event handlers, and on_load seems like it should be called on window load, not a form submission.




回答2:


Also add the following line :

y.style.display = "block";


来源:https://stackoverflow.com/questions/40721522/hidden-dom-element-containing-the-message-and-to-make-it-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!