PHP:根据复选框获取工作日和休息日

时间:2016-11-07 07:27:00

标签: javascript php html

所以这就是我到目前为止所做的事情,但我想不出用PHP获取每天输入或检查数据的方法。由于我对工作日的所有输入类型都有相同的名称,即name ='work'。我无法找到一种方法来单独获取每一天的值(使用PHP)。

<body>
    <center>
        <form method="post" action="Acharges.php">
            <table>
                <tr>
                    <td colspan="4"><input type="checkbox" onclick="toggle(this)" name="day" /><b>All Day</b></td>
                    <td><b>Working</b></td>
                    <td><b>Close</b></td>
                </tr>

                <tr>
                    <td colspan="4"><b>Monday</b></td>
                    <td><input type="checkbox" name="work" value="work" /></td>
                    <td><input type="checkbox" name="mday" /></td>
                </tr>

                <tr>
                    <td colspan="4"><b>Tuesday</b></td>
                    <td><input type="checkbox" name="work" value="work" /></td>
                    <td><input type="checkbox" name="tday" /></td>
                </tr>

                <tr>
                    <td colspan="4"><b>Wednesday</b></td>
                    <td><input type="checkbox" name="work" value="work" /></td>
                    <td><input type="checkbox" name="wday" /></td>
                </tr>

                <tr>
                    <td colspan="4"><b>Thursday</b></td>
                    <td><input type="checkbox" name="work" value="work" /></td>
                    <td><input type="checkbox" name="thday" /></td>
                </tr>

                <tr>
                    <td colspan="4"><b>Friday</b></td>
                    <td><input type="checkbox" name="work" value="work" /></td>
                    <td><input type="checkbox" name="fday" /></td>
                </tr>

                <tr>
                    <td colspan="4"><b>Saturday</b></td>
                    <td><input type="checkbox" name="work" value="work" /></td>
                    <td><input type="checkbox" name="sday" value="close" /></td>
                </tr>

                <tr>
                    <td colspan="4"><b>Sunday</b></td>
                    <td><input type="checkbox" name="work" value="work" /></td>
                    <td><input type="checkbox" name="suday" /></td>
                </tr>
            </table>
            <br />
            <br />
            <b>Number Of Employees:</b><input type="number" max="20"    min="1" name="noe" placeholder="1 - 20" /> <br /> <br />
            <table>
                <tr>
                    <td><b>Buisness Details:</b></td>
                    <td><input type="date" name="doe"
                        placeholder="Date Of Establishment" /></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="number" name="a_tover" placeholder="ANNUAL TURNOVER" /></td>
                </tr>
            </table>
        </form>
    </center>
    <script language="javascript">
        function toggle(source) {
            checkbox = document.getElementsByName('work');
            for (var i = 0, n = checkbox.length; i < n; i++) {
                checkbox[i].checked = source.checked;
            }
        }
    </script>
</body>

1 个答案:

答案 0 :(得分:0)

<html>
<head>
    <script>
        var workdays=[0,0,0,0,0,0,0];
        var days=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
        var allcheckbox = document.getElementsByName('work');

        function checkcheckbox(arr,checked){    
            for (var i = 0; i < checked.length; i++) {
                if(checked[i].checked){
                    arr[i]=1;
                }else{
                    arr[i]=0;
                }
            }
            console.log(arr);
        }

        function print(arr,days){
            for (var i = 0; i < arr.length; i++) {
                if(arr[i]==0){
                    console.log(days[i]+": close");
                }else{
                    console.log(days[i]+": workday");
                }
            }
        }

        function toggle(source) {
            checkbox = document.getElementsByName('work');
            for (var i = 0, n = checkbox.length; i < n; i++) {
                checkbox[i].checked = source.checked;
            }
        }
    </script>
</head>
<body>
    <center>
        <form method="post" action="Acharges.php">
            <table>
                <tr>
                    <td colspan="4"><input type="checkbox" onclick="toggle(this)" name="day" /><b>All Day</b></td>
                    <td><b>Working</b></td>
                </tr>

                <tr>
                    <td colspan="4"><b>Monday</b></td>
                    <td><input type="checkbox" name="work" value="work" /></td>
                </tr>

                <tr>
                    <td colspan="4"><b>Tuesday</b></td>
                    <td><input type="checkbox" name="work" value="work" /></td>
                </tr>

                <tr>
                    <td colspan="4"><b>Wednesday</b></td>
                    <td><input type="checkbox" name="work" value="work" /></td>
                </tr>

                <tr>
                    <td colspan="4"><b>Thursday</b></td>
                    <td><input type="checkbox" name="work" value="work" /></td>
                </tr>

                <tr>
                    <td colspan="4"><b>Friday</b></td>
                    <td><input type="checkbox" name="work" value="work" /></td>
                </tr>

                <tr>
                    <td colspan="4"><b>Saturday</b></td>
                    <td><input type="checkbox" name="work" value="work" /></td>
                </tr>

                <tr>
                    <td colspan="4"><b>Sunday</b></td>
                    <td><input type="checkbox" name="work" value="work" /></td>
                </tr>
            </table>
            <br />
            <input type="button" value="SEND" onclick="checkcheckbox(workdays,allcheckbox)"/>
            <input type="button" value="SEND" onclick="print(workdays,days)"/>
        </form>
    </center>
</body>
</html>