Form text fields (input:text)
In this chapter you will learn:
- Description and Syntax for Form text fields selector
- Examples for form text fields selector
- Select text input element inside a form
Description and Syntax
$(":text")
selects all text fields (<input type="text">
).
Examples
The following code counts the text fields for a form.
<html><!-- j a va 2s .co m-->
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
alert($(":text").length);
});
</script>
</head>
<body>
<body>
<form>
<input type="button" value="Input Button"/>
<input type="checkbox">asdf</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>
Select text input element
The following code selects text input element inside a form.
<html><!--from ja v a 2 s .c o m-->
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var input = $("form input:text");
$("div").text("For this type jQuery found " + input.length + ".");
});
</script>
</head>
<body>
<form>
<input type="text" >java2s.com</input>
</form>
<div></div>
</body>
</html>
Next chapter...
What you will learn in the next chapter: