HTML select what is the name of on select event?
Is onchange
what you're looking for?
onselect event in HTML option/option tag
Trigger the Change Event of the SELECT on the page load.
Try this:
<script type="text/javascript">
window.onload = function(){
var category = document.getElementById("category");
category.onchange();
}
</script>
adding onclick event to html select option
Try it in the onchange handler:
function checkAlert(evt) { if (evt.target.value === "Say Hello") { alert('Hello'); }}
<select onchange="checkAlert(event)"> <option>Test</option> <option>Say Hello</option></select>
Pass the whole data to the onChange in a select tag
So I came up with a brute force approach. since you need to pass the id of the item to a LoadNew function
export default function App() {
let data = [
{ name: "Love", id: 1 },
{ name: "labs", id: 2 }
];
return (
<div className="App">
<select
onChange={(e) => {
let item= data.filter((val) => val.name == e.target.value);
LoadNew(item.id)
}}
>
{data.map((item) => {
return (
<>
<option value={item.name} key={item.id}>
{item.name}
</option>
</>
);
})}
</select>
</div>
);
}
You can get the selected value by placing an onChange event Listener on the select tag. We then filter the data to get the specific item, after we pass the item's id to the function.
How to use onClick() or onSelect() on option tag in a JSP page?
Neither the onSelect()
nor onClick()
events are supported by the <option>
tag. The former refers to selecting text (i.e. by clicking + dragging across a text field) so can only be used with the <text>
and <textarea>
tags. The onClick()
event can be used with <select>
tags - however, you probably are looking for functionality where it would be best to use the onChange()
event, not onClick()
.
Furthermore, by the look of your <c:...>
tags, you are also trying to use JSP syntax in a plain HTML document. That's just... incorrect.
In response to your comment to this answer - I can barely understand it. However, it sounds like what you want to do is get the value of the <option>
tag that the user has just selected whenever they select one. In that case, you want to have something like:
<html>
<head>
<script type="text/javascript">
function changeFunc() {
var selectBox = document.getElementById("selectBox");
var selectedValue = selectBox.options[selectBox.selectedIndex].value;
alert(selectedValue);
}
</script>
</head>
<body>
<select id="selectBox" onchange="changeFunc();">
<option value="1">Option #1</option>
<option value="2">Option #2</option>
</select>
</body>
</html>
Related Topics
Why Is "Element.Innerhtml+=" Bad Code
How to Scroll an HTML Page to a Given Anchor
Jquery: How to Call Resize Event Only Once It's Finished Resizing
How to Get the Raw Value an ≪Input Type="Number"≫ Field
Why Does Canvas.Todataurl() Throw a Security Exception
When Do Items in Html5 Local Storage Expire
How to Get the Entire Document HTML as a String
Adding Input Elements Dynamically to Form
Way to Ng-Repeat Defined Number of Times Instead of Repeating Over Array
Page Content Is Loaded With JavaScript and Jsoup Doesn't See It
How to Wait For the 'End' of 'Resize' Event and Only Then Perform an Action
How to Render an 'Atmosphere' Over a Rendering of the Earth in Three.Js
How to Calculate the Number of Days Between Two Dates
How to Render HTML String as Real Html
JavaScript Not Running on Jsfiddle.Net
Which Browsers Support ≪Script Async="Async" /≫
How to Cancel Form Submission in Submit Button Onclick Event