Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7734851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:21:15+00:00 2026-06-01T07:21:15+00:00

I’ve read a few articles talking about checkboxes always returning a false state, but

  • 0

I’ve read a few articles talking about checkboxes always returning a false state, but haven’t found anything about my own problem.

So, here is the script:

<script type="text/javascript">
    function update_contact(id, name) {
        alert("idCont : " + id + "\n nameCKB : " + name + "\n state : "
                + $(this).attr('checked'));
        var a = location.pathname.substring(1).split('/')
        $.ajax({
            url : '@Url.Action("update_contact")',
            type : 'POST',
            data : {
                name : name,
                isChecked : $(this).is(':checked'),
                idOpp : a[2],
                idCont : id
            },
            success : function(result) {
            }
        });
    };
</script>

And here is the checkbox’s code :

@If mail = False Then
    @<input type="checkbox" name="mailed" id="mailed" class="mailed" onclick="update_contact(@item.idContact.toString() , 'mailed')" />
Else
    @<input type="checkbox" name="mailed" id="mailed" class="mailed" onclick="update_contact(@item.idContact.toString() , 'mailed')" checked="checked" />
End If

And here is the code generated by the server :

<input name="mailed" id="mailed" class="mailed" onclick="update_contact(1 , 'mailed')" type="checkbox">

In the beginning, I used a Html helper. It was returning smth like that:

<input id="mailed" name="mailed" onclick="update_contact(1 ,'mailed')" value="true" type="checkbox">
<input name="mailed" value="false" type="hidden">

I though it was due to the second input that it was always returning a false state.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:21:16+00:00Added an answer on June 1, 2026 at 7:21 am

    The problem is likely that this is not what you think it is. Try explicitly passing a reference to the clicked checkbox to your function:

    @If mail = False Then
          @<input type="checkbox" name="mailed" id="mailed" class="mailed" onclick="update_contact(@item.idContact.toString() , 'mailed', this)" />
    Else
          @<input type="checkbox" name="mailed" id="mailed" class="mailed" onclick="update_contact(@item.idContact.toString() , 'mailed', this)" checked="checked" />
    End If
    

    And then:

        function update_contact(id, name, cb) {
            alert("idCont: " + id + "\n nameCKB: " + name + "\n state: " + cb.checked);
            // you could say $(cb).attr("checked"), but cb.checked is more efficient
            // and easier to read
            var a = location.pathname.substring(1).split('/')
            $.ajax({
                url: '@Url.Action("update_contact")',
                type: 'POST',
                data: { 
                        name: name, 
                        isChecked: cb.checked, 
                        idOpp: a[2], 
                        idCont: id
                },
                success: function (result) {}
            });
        };
    

    Alternatively use jQuery to assign the click handler and it will set this for you correctly. You could put the @item.idContact.toString() in the value attribute and then access it using this.value in your handler:

    @If mail = False Then
          @<input type="checkbox" name="mailed" id="mailed" class="mailed" value="@item.idContact.toString()" />
    Else
          @<input type="checkbox" name="mailed" id="mailed" class="mailed" value="@item.idContact.toString()" checked="checked" />
    End If
    

    And then:

     $(document).ready(function() {
        $("#mailed").click(function() {
            alert("idCont: " + this.value + "\n nameCKB: " + this.name + "\n state: " + this.checked);
            // you could say $(this).attr("checked"), but this.checked is more efficient
            // and easier to read
            var a = location.pathname.substring(1).split('/')
            $.ajax({
                url: '@Url.Action("update_contact")',
                type: 'POST',
                data: { 
                        name: this.name, 
                        isChecked: this.checked, 
                        idOpp: a[2], 
                        idCont: this.value
                },
                success: function (result) {}
            });
        });
    });
    

    (Note: I don’t actually know the VB/razor syntax, I’m just guessing on that part.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I want to construct a data frame in an Rcpp function, but when I
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.