mardi 4 août 2015

Check boxes not working

Help, there is something wrong with my checkboxes. I'm trying to make a form with checkboxes. However, when I tick only one checkbox, all the checkboxes will also be ticked and the data will be inserted into the database.

This is my code below,

$(document).ready(function () {

        function showComment() {
            $.ajax({
                type: "post",
                url: "registerarray.php",
                data: "action=showcomment",
                success: function (data) {
                    $("#comment").html(data);
                }
            });
        }
        showComment();

        $("#send").click(function () {

            var starttime = $("#starttime").val();
            var endtime = $("#endtime").val();
            var monday = $("#monday").val();
            var tuesday = $("#tuesday").val();
            var wednesday = $("#wednesday").val();
            var thursday = $("#thursday").val();
            var saturday = $("#saturday").val();
            var friday = $("#friday").val();
            var sunday = $("#sunday").val();

            var dataString = "starttime1=" + starttime + "&endtime1=" + endtime + "&monday1=" + monday + "&tuesday1=" + tuesday + "&wednesday1=" + wednesday + "&thursday1=" + thursday + "&friday1=" + friday + "&saturday1=" + saturday + "&sunday1=" + sunday + "&action=addcomment";

            $.ajax({
                type: "post",
                url: "registerarray.php",
                data: dataString,
                success: function (data) {
                    showComment();
                    $("#formTable")[0].reset();

                }

            });

        });
    });

<div id="formbox"> 
                <form id="formTable">

                    <div class="form-group">
                        <div class="col-md-2">
                            <lable>Start time</lable>
                            <input type="text" class="form-control" name="startTime" id="starttime">
                        </div>
                        <div class="col-md-2">
                            <lable>End time</lable>
                            <input type="text" class="form-control" name="endTime" id="endtime">
                        </div>
                    </div>

                    <div class="form-group">
                        <lable>Monday</lable>
                        <input type="checkbox" name="Monday" value="1" id="monday">
                        <lable>Tuesday</lable>
                        <input type="checkbox" name="Tuesday" value="1" id="tuesday">
                        <lable>Wednesday</lable>
                        <input type="checkbox" name="Wednesday" value="1" id="wednesday">
                        <lable>Thursday</lable>
                        <input type="checkbox" name="Thursday" value="1" id="thursday">
                        <lable>Friday</lable>
                        <input type="checkbox" name="Friday" value="1" id="friday">
                        <lable>Saturday</lable>
                        <input type="checkbox" name="Saturday" value="1" id="saturday">
                        <lable>Sunday</lable>
                        <input type="checkbox" name="Sunday" value="1" id="sunday">
                    </div>

                    <div class="form-group">
                        <input type="button" class="btn btn-success" value="Add" id="send">
                    </div>

                </form>
            </div>

Please help thanks




Aucun commentaire:

Enregistrer un commentaire