HTML onselect attribute
onselect
The purpose of the HTML onselect attribute is to execute the code specified, when some text of the associated element is selected.
Supported elements
HTML onselect attribute supports input and textarea elements.
Syntax
<ElementName onselect="value" >.....</ElementName>
Where ElementName is any supported element.
Type of value
Script.
Value
A script which is to be executed.
Default value
There is no default value of HTML onselect attribute.
Supported doctypes
HTML 4.01 strict, HTML 4.01 transitional, HTML 4.01 frameset.
Example of HTML onselect attribute with input and textarea elements
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML onselect attribute with input and textarea elements</title>
</head>
<body>
<form name="user_info" action="action.php" method="post">
Name : <input type="text" name="name" onselect="alert('some text of this field is selected')"><br>
email : <input type="text" name="email" onselect="alert('some text of this field is selected')"><br>
Describe yourself : <br>
<textarea rows="10" cols="10" name="describe_yourself" onselect="alert('some text of this field is selected')">
</textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Result

View this example in a separate browser window
Example of HTML onselect attribute with input and textarea elements
Previous: HTML onreset attribute
Next: HTML onsubmit attribute
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook