简体   繁体   English

未调用Javascript函数onclick()和onsubmit()

[英]Javascript Function is not Called onclick() and onsubmit()

Can anyone tell me why below javascript functions are not calling while clicking the button or submitting the form. 谁能告诉我为什么单击按钮或提交表单时没有调用下面的javascript函数。

I am not getting wht is the wrong with this code. 我不明白这是错误的代码。 Please help 请帮忙

 <script type="text/javascript"> function confrm() { alert("check1"); if(confirm("Are you going to submit this form?")==true) { return true; } else { return false; } } function checkfrm() { var selcteddate=document.newrequest.sel.value; var sdate=new Date(selcteddate); alert("check 2"); if(document.newrequest.server.value=="select") { alert("Select server"); return false; } else { return true; } } </script> <form id="newrequest" name="newrequest" method=post action="cgi-bin/newrequest.cgi" onsubmit="return checkfrm();"> <td colspan=2> <input type="submit" id="submit" name="submit" value="Submit" onclick="return confrm();" /> </td> 

You can do it without return. 您可以做而无需退货。 Try this : 尝试这个 :

<script type="text/javascript">
    function confrm(){
        alert("check1");
        if(confirm("Are you going to submit this form?")==true) {               
            document.getElementById("newrequest").submit();
        }else{
            return false;
        }
    }
    </script>
<form id="newrequest" name="newrequest" method="post" action="cgi-bin/newrequest.cgi" onsubmit="checkfrm();">
<td colspan=2>
<input value="Submit" type="input" onclick="confrm();" />
</td>

You can find the guide for onclick event on http://www.w3schools.com/jsref/event_onclick.asp and Submit guide on http://www.w3schools.com/jsref/met_form_submit.asp 您可以在http://www.w3schools.com/jsref/event_onclick.asp上找到onclick事件的指南,并在http://www.w3schools.com/jsref/met_form_submit.asp找到“提交指南”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM