Form Radio button (input:radio)
In this chapter you will learn:
- Description and Syntax for Form Radio button selector
- Examples for Form Radio button selector
- How to find radio button within the first form
Description and Syntax
$(":radio")
selects all radio button fields (<input type="radio">
).
Examples
The following code counts the radio button element for a form.
<html><!--from j a v a2s .co m-->
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
alert($(":radio").length);
});
</script>
</head>
<body>
<body>
<form>
<input type="button" value="Input Button"/>
<input type="checkbox">java2s.com</input>
<input type="checkbox" />
<input type="checkbox" />
<input type="file" />
<input type="hidden" />
<input type="image" />
<input type="password" />
<input type="radio" />
<input type="reset" />
<input type="submit" />
<input type="text" />
<select><option>Option<option/></select>
<textarea></textarea>
<button>Button</button>
</form>
</body>
</html>
Find radio button within the first form
Finds all inputs of type radio within the first form in the document
<html><!--from j a va2s.c o m-->
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
alert($("input:radio", document.forms[0]).length);
});
</script>
</head>
<body>
<form>
<input type="radio" value="Option">
</form>
</body>
</html>
Next chapter...
What you will learn in the next chapter: