php - 表单 2 按钮 + javascript 问题

标签 php javascript html

<form action="index.php?page=checkin" method="post" name="regForm">
    <div id="First_1">
        <table width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    <table cellpadding="0" cellspacing="5">
                        <tr>
                            <td style="padding: 5px;">
                                Fullständiga namn:
                            </td>
                            <td>
                                <input name="full_name" type="text" id="full_name" class="required">
                            </td>
                        </tr>
                        <tr>
                            <td style="padding: 5px;">
                                Email:
                            </td>
                            <td>
                                <input name="usr_email" type="text" id="usr_email3" class="required">
                            </td>
                        </tr>
                        <tr>
                            <td style="padding: 5px;">
                                Sex:
                            </td>
                            <td>
                                <select name="sex">
                                    <option value="male">
                                        Kille
                                    </option>
                                    <option value="female">
                                        Tjej
                                    </option>
                                </select>
                            </td>
                        </tr>
                        <td>
                            <input type="submit" id="continue" value="Fortsätt">
                        </td>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    <div id="Next_2" style="display: none">
        <table width="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    <table cellpadding="0" cellspacing="5">
                        <tr>
                            <td style="padding: 5px;">
                                Lösenord:
                            </td>
                            <td>
                                <input name="pwd" type="password" class="required password" id="pwd">
                            </td>
                            <td>
                                En gång till..
                            </td>
                            <td>
                                <input name="pwd2" id="pwd2" class="required password" type="password">
                            </td>
                            <td>
                                <input name="doRegister" type="submit" id="doRegister" value="Register">
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
</form>
<script type="text/javascript">
    $(function() {
        $("#continue").click(function() {
            $.ajax({
                type: "POST",
                url: "dbc.php",
                data: {
                    check: 'First',
                    full_name: $('#full_name').val(),
                    usr_email: $('#usr_email3').val()
                },
                success: function(msg) {
                    if (msg == '1') {
                        $("#First_1").hide();
                        $("#Next_2").toggle();
                    } else {
                        alert(msg);
                    }
                }
            });
            return false;
        });
    });
</script>

这就是我的表格。您首先填写 3 个表单元素,然后按“继续”按钮,然后它会发送 ajax 调用来检查字段。如果一切正常(如果 ajax 调用的输出 = 1),Next_2 将打开,您可以在其中输入密码两次。之后,您按最后一个按钮“注册”,它应该执行“action=index.php?page=checkin”,但事实并非如此,当我按“注册”时,它只是变成空白,我可以在 firebug 中看到它发送另一个 ajax 调用我无法理解,因为该按钮没有 id="continue"但 id="doRegister"

最佳答案

由于“继续”按钮实际上并不提交表单,因此尝试将其声明为普通按钮而不是提交按钮,如下所示:

<input type="button" id="continue" value="Fortsätt">

我猜测同一表单上有两个提交按钮会以某种方式导致与处理程序的交互。

关于php - 表单 2 按钮 + javascript 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3382610/

相关文章:

php - PHP 中的 Navmenu 与 Mysql 作为递归数据 - 使用 3 个不同的表

php - 需要标签的项目的 Wordpress 小部件更新实例

javascript - Google Apps 脚本 : How to check if a calendar event has been marked as deleted manually

javascript - 需要禁用部分的超链接背景

html - Divi 下拉菜单水平而不是垂直

php - Laravel 查询在 id 列上返回 Null id

php - 什么时候应该使用 Doctrine ORM,什么时候应该使用 zend-db-table?

javascript - 如何从 URL 获取状态变量值

javascript 焦点在加载时不起作用

html - 将 2 个 DIV 放在彼此的顶部