0

I have Javascript Function that works correctly when the checkbox is checked i.e. sets 'Chk' to true but not when the checkbox is unchecked i.e. also sets 'Chk' to true. The Function then passes two parameters to a second page which runs a Stored Proc (setting a value to true or false). Here is my code:

    <script src="Scripts/jquery-1.4.1.js" type="text/javascript" language="javascript"></script>
<script type="text/javascript">
    function myfunction(invId, Chk) {
    var chkboxValue = ($("#iSelect").is(":checked") ? false : true);
    $.ajax({
        type: "GET",
        url: "upDateMe.aspx?param1=" + invId +"&param2=" + chkboxValue,
        data: "",
        contentType: "text/html",
        dataType: "text"
    });
}

3
  • 1
    What happens when the checkbox is unchecked? Doesn't work is not enough information :) Commented Jun 6, 2013 at 18:42
  • how do you call your function? Commented Jun 6, 2013 at 18:43
  • And the question is...? Commented Jun 6, 2013 at 18:43

1 Answer 1

1

You can get the checkbox status value by using this

var chkboxValue = ($("#iSelect").prop('checked'));

this will fetch whether it is true or false Your function should like this

function myfunction(invId, Chk) {
    var chkboxValue = ($("#iSelect").prop('checked'));
    $.ajax({
        type: "GET",
        url: "upDateMe.aspx?param1=" + invId +"&param2=" + chkboxValue,
        data: "",
        contentType: "text/html",
        dataType: "text"
    });
}

Here is the fiddle that you want: http://jsfiddle.net/QRNyJ/1/

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks but I get - Microsoft JScript runtime error: Object doesn't support property or method 'prop'
You should use jquery 1.6 or greater

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.