输入类型=按钮,就像它是type = submit一样

时间:2012-11-28 11:10:16

标签: javascript button javascript-events input

我需要两个输入不同类型

<input  type="button"  **onclick = "?????"**   name="back"  value="&#8592 Back"  >
<input  type="submit" name="submit" value="Forward &#8594"  >

我怎么能为type = button运行这个php代码:

<?php

    if (isset($_POST['back']))
    {

        $_SESSION['onpage'] = $_SESSION['onpage'] - 1;

        $query_questionset = "
        select Q.Constructor AS Constructor,
        QS.QuestionIDFKPK AS QuestionIDFKPK,
        Q.QuestionValue AS QuestionValue,
        QS.SortOrder AS SortOrder,
        QS.onpage AS onpage
        from tbluserset AS US
        inner join tblquestionset AS QS ON US.QuestionSetIDFKPK = QS.QuestionSetIDPK
        inner join tblquestion AS Q ON QS.QuestionIDFKPK = Q.QuestionIDPK
        where (US.UserIDFKPK = " . $UserId . ")
        and (US.UserSetIDPK= '" . $_SESSION['UserSetIDPK'] . "')
        and (QS.onpage = '" . $_SESSION['onpage'] . "')
        order by QS.SortOrder";

    }

    $QuestionSet_Constructors = mysql_query($query_questionset);
?>

我的表单和输入提交工作完美:

<form id= "formID"  class="formular"   method="post" action= "<?= $url = "QUESTIONAREnewdatabase.php"; ?>" accept-charset="utf-8">

我需要在input type=button上运行php代码和操作表单,如果Back有type=submit

3 个答案:

答案 0 :(得分:0)

试试这个

< input type="submit" onclick = "?????" name="back" value="&#8592 Back" >

答案 1 :(得分:0)

<form action="" id="formID" class="formular" method="post" accept-charset="utf-8">
    <!-- Your inputs here -->
    <button type="submit" name="back">&#8592 Back</button>
    <button type="submit" name="submit">Forward &#8594</button>
</form>

答案 2 :(得分:0)

这是使用Javascript的一种方式,这将动态创建并向表单附加名为back的隐藏输入,然后提交表单 - 单击后退按钮时。

<script>
    function postBack()
    {
        var myForm = document.getElementById("formID");
        var backInput = document.createElement("input");
        backInput.type = "hidden";
        backInput.name = "back";
        backInput.value = "1";

        myForm.appendChild(backInput);
        myForm.submit();
    }
</script>


<input type="button" onclick="postBack()" name="back" value="&#8592 Back">

在服务器端,您现在可以测试:

if(isset($_POST['back']))
{
    // back was pressed...
}