简体   繁体   English

如何在单击时禁用提交按钮并将表单数据提交到Perl脚本?

[英]how to disable a submit button on clicking and submit the form data to perl script?

i have a html form. 我有一个HTML表单。 when the submit button is pressed, a perl script is called and the form data is submitted to the perl script. 当按下提交按钮时,将调用一个perl脚本,并将表单数据提交到该perl脚本。 the form contains a text box and a submit button. 该表单包含一个文本框和一个提交按钮。 the submit button also validates whether the text box contains some value or not. 提交按钮还可以验证文本框是否包含某些值。 and if it contains ot submits the form else it alerts a message. 如果包含ot,则提交该表单,否则将警告消息。 below is the sample code: 下面是示例代码:

<html>
        <head>
                <title>files move</title>

                <script type="text/javascript">

                  function check_filename()
                  {
                                if (!frm1.FileName.value)
                                {
                                        alert ("No File is selected to Move");
                                        return false;
                                }
                                else
                          {
                                        document.getElementById("btn_sbmt").disabled = 'true'
                                        return true;
                          }
                  }
                </script>
        </head>

    <body>

                <form id="frm1" name="frm1" action="/cgi-bin/sample_move.pl" method="GET">

            <input type="text" name="FileName" id="FileName">
                        <input type="submit" name="btn_sbmt" id="btn_sbmt" value="MOVE FILES" onclick="return check_filename();">

                </form>
        </body>
</html> 

when i click on the submit button, i want to 1st check whether the text box contain some value or not. 当我单击提交按钮时,我想首先检查文本框是否包含某些值。 If it contains then i want to call the perl script and disable the submit button to avoid clicking the submit button multiple times. 如果包含,则我想调用perl脚本并禁用“提交”按钮,以避免多次单击“提交”按钮。 the above code checks whether the text box is empty or not and if it is not empty then it disables the submit button but it does not submit the form to perl script. 上面的代码检查文本框是否为空,如果不为空,则禁用提交按钮,但不将表单提交给perl脚本。 can anyone tell how to do this? 谁能告诉我该怎么做?

This sample is based on your example. 该示例基于您的示例。

function check_filename()
{
    if (!frm1.FileName.value)
    {
        alert ("No File is selected to Move");
        return false;
    }
    else
    {
        document.getElementById("btn_sbmt").disabled = 'true';
        document.getElementById("frm1").submit();
        return true;
     }
}

For a cleaner version, you can use jQuery. 对于更干净的版本,可以使用jQuery。 http://api.jquery.com/submit/ http://api.jquery.com/submit/

在您的其他部分添加此行

document.getElementById("frm").submit();

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

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