Hidden DOM element containing the message and to m

2019-09-15 01:30发布

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>

2条回答
我只想做你的唯一
2楼-- · 2019-09-15 01:49

Also add the following line :

y.style.display = "block";
查看更多
Luminary・发光体
3楼-- · 2019-09-15 02:03

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.

查看更多
登录 后发表回答