onselect
onselect
The onselect
event attribute in HTML is activated when a user selects text in an <input>
field or a <textarea>
. This event enables developers to trigger specific actions or scripts in response to text selection, improving user interaction and overall experience.
Syntax
In HTML
<element onselect="myScript">
In JS
object.onselect = function(){myScript};
addEventListener()
function is used. In JavaScript, the
object.addEventListener("select", myScript);
Example
<!DOCTYPE html>
<html>
<body>
Select some of the text: <input type="text" value="Hello world!" onselect="myFunction()">
<script>
function myFunction() {
alert("You selected some text!");
}
</script>
</body>
</html>
Values
Conclusion
The onselect
event improves user interaction by allowing <script>
to respond when text is selected within form elements. It enables developers to create dynamic actions based on user selection.
onsearch
The onsearch event in HTML is activated when a user starts a search within an input field, enabling scripts to respond to search activities.
onsubmit
The onsubmit event in HTML is triggered when a <form> is submitted, allowing scripts to validate the data or perform actions before the <form> submission is completed.