问题
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" > <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