html中的输入标记在添加onclick javascript时不发送POST变量

时间:2017-12-11 08:52:35

标签: javascript php html css

这有效..

<form name="form1" action="test.php" method="post">
table class="questiontable" border="0">
<tr><td><input type="submit" name="previous_question" id="previous_question" value="Previous Question"></td></tr>
</table>
</form>

<?php
echo $_POST["previous_question"] ;
?>

输出

Previous Question

然而,这不起作用并给出空白输出。 (请等待和禁用按钮工作)

<form name="form1" action="test.php" method="post">
<table class="questiontable" border="0">
<tr><td><input type="submit" onclick="this.disabled=true; this.value='Please Wait...'; this.form.submit();" name="previous_question" id="previous_question" value="Previous Question"></td></tr>
</table>
</form>

<?php
echo $_POST["previous_question"] ;
?>

我需要等待点击以防止用户点击两次。问题是POST变量在完成后不会通过。我需要POST变量来检查按下了哪个提交按钮,因为我的表单有很多。

请建议我做错了什么。

感谢。

3 个答案:

答案 0 :(得分:0)

试试这个:

function foo () {
    getElementByName("previous_question").value("please wait...");
    getElementByName("form1").submit();
    getElementByName("previous_question").disabled = true;
}

然后使用onclick

调用此函数

答案 1 :(得分:0)

试试这个

Function COMBINE(rng As Range)
    Dim cell As Range
    Dim text As String
    For Each cell In rng

        If IsEmpty(cell.Value) Then
            Exit For
        Else
            text = text & cell.Value & ","
        End if

    Next cell

    COMBINE = text

End Function

答案 2 :(得分:0)

<form name="form1" action="test.php" method="post" onsubmit="event.preventDefault(); submitnow();">
   <table class="questiontable" border="0">
     <tr><td><input type="submit" name="previous_question" id="previous_question" value="Previous Question"></td></tr>
</table>
</form>

<script type="text/javascript">
function submitnow(){
    var id = document.getElementById('previous_question');
    id.disabled = true;
    id.value = 'Please Wait...';
    setTimeout(function(){
        document.form1.submit();
        id.disabled = false;
        id.value = 'Previous Question';
    }, 2000);
}
</script>