Resolved checked selector not wotking

learner

Member
Joined
Sep 26, 2020
Messages
8
Programming Experience
Beginner
C#:
this is the html
<div>
    <input type="checkbox" name="skills" value="js" />JS
    <input type="checkbox" name="skills" value="jQuery" />jQuery
    <input type="checkbox" name="skills" value="C#" />c#
    <input type="checkbox" name="skills" value="VB" />VB
    <br /><br />
    <input id="btn1"  class ="btn btn-outline-info" type ="submit"  />


    <div id="result1">
      

    </div>
</div>


this is in the site.js file

$(document).ready(function () {
    $('#btn1').click(function () {
       var result = $('input[type="checkbox"]:checked');
        if (result.length > 0) {
            var resultString = result.length + "  checkbox checked <br/>";
        
            result.each(function () {

                resultString += $(this).val() + "<br/>";
            });
            $('#result1').html(resultString);
        }
        else {
            $('#result1').html("none selected");
        }
    });

})

the output should be something like this :
none selected , if no checkbox is selected and like this
1601373104574.png
:
if checkbox are selected.
there is no output if the submit button is clicked. I am not sure what is wrong in the code.
 
Typically, the submit type button only works when it is in a <form>.

We can't really help you much with just the HTML you are showing us. Where is the the associated code?
 
Typically, the submit type button only works when it is in a <form>.

We can't really help you much with just the HTML you are showing us. Where is the the associated code?
Actually I am learning jQuery , so this was an example to show how the checkbox selector works to print which checkbox has been selected. It is not part of anything, just little code by itself.
 
I see... and so how is this a C# question?
 
I see... and so how is this a C# question?
I have been told that C# developers are usually full stack developers , and jQuery is part of it. So I thought someone might know this. And also this was posted under the design section , which I thought comes under front end , that is the reason I posted here.
 
Not all C# developers deal with Web technologies.
 
What type of project/and language are you running that code in?

I would first suggest you run the later code in a validator and you will notice it doesn't parse. There are plugins you can use to help you with development. I know there is one for Mozila Browser for JQuery, because I used to use it when I used to use that browser.
 
Back
Top Bottom