w3resource

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

html onselect attribute with input and textarea elements

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.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/html/attributes/html-onselect-attribute.php