1

I am trying to get the value from the Kendoui Checkbox but without success so far.

<input type="checkbox" id="telephonyeq1" name="telephonychk[]" class="k-checkbox telephonycb">

The script

<script>
    if($('#telephonyeq1').is(":checked"))
        {
        var telephonycb = "true"
        }
        else {
        var telephonycb = "false"
        }
</script>

when i am POST the data through AJAX i am always receiving value as "False", even if it's checked or unchecked.

Telephony: false 

And the Ajax

        $("#save").click(function() {
            $.ajax({
                url: "/test",
                method: "post",
                data: { 
                     .....
                    "telephonycb": telephonycb,
                    "internetcb": internetcb,
                    "_token": "{{ csrf_token() }}"
                },
                success: function(data) {
                    if($.isEmptyObject(data.error)){
                        printSuccessMsg(data.success);

                    } else{
                        printErrorMsg(data.error);
                    }
                }

            }); 

        }); 
        function printErrorMsg (msg) {
            ......
        }
        function printSuccessMsg (msg) {
            $(".print-error-msg").find("ul").html('');
            $(".print-error-msg").css('display','none');
            $(".print-success-msg").css('display','block');
            $("h5 span").html(
                '<br /><h5><strong>Incident Description</strong>
                .......
                '</code><br /><h5><strong>Impact on Services</strong></h5>Telephony: <code>' + telephonycb + '</code> Service Issues <code>' + telephony.value() + '</code> - Affected Users: <code>' + telephonyaffected.value() +
                '</code><br />Internet: <code>' + internetcb + '</code> Service Issues <code>' + internet.value() + '</code> - Affected Users: <code>' + internetaffected.value() +
                ......
                );

        }

    });
</script>

2 Answers2

0

update the line inside the ajax

"telephonycb": (($('#telephonyeq1:checked').length > 0) ? "true ": "false"),
Anfath Hifans
  • 1,550
  • 1
  • 8
  • 18
0

If what you are trying is sending the value telephonycb through Ajax, it's always going to be false.

The script you have is executed only once at load time. If you want to keep the variable, you can add the function change so it updates the variable when you click the box.

Example:

$('#telephonyeq1').change(function(){
    if($('#telephonyeq1').is(":checked"))
        {
           var telephonycb = "true"
        }
        else {
           var telephonycb = "false"
        }
});
Juliosor
  • 131
  • 1
  • 8