$("input:checkbox:checked").val()



Description

This gets the first value from a checked checkbox.

Syntax

Here is the simple syntax to use this method −

selector.val();

Parameters

None

Example

Following example gets the first value from a checked checkbox.

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>		
      <script type = "text/javascript" language = "javascript">	 
         function show(){
            alert($("input:checkbox:checked").val());
         }
      </script>
   </head>	
   
   <body>
      <div>
         <form name = "sampleForm">
            <input type = "checkbox" id = "result1" title="The jQuery Example" value = "red" >red</input><br/><br/>
            <input type = "checkbox" id = "result2" title="The jQuery Example" value = "green" >green</input> <br/><br/>
            <input type = "button" id = "submitButton" onclick="show();" value = "submit"/>
         </form>
      </div>
   </body>	
</html>

This will produce following result −

jqueryexamples_attributes.htm
Advertisements