Reputation: 284
I am using this oninput="setCustomValidity('')
on input
tag perfectly but it not seem to be working in a select
tag. Is this valid in select
tag?.
<select class="dropdownlist" required oninvalid="this.setCustomValidity('Please select Accused Name')" oninput="setCustomValidity('')">
Upvotes: 8
Views: 21096
Reputation: 4951
It looks like all browsers support oninput
on the <select>
element in 2023.
The input event is fired when the user changes the value of an
<input>
element,<select>
element, or<textarea>
element. By contrast, the "change" event usually only fires after the form control has lost focus.
Upvotes: 0
Reputation: 27614
You can not use oninput
attribute. you can use onchange
attributes instead of oninput
.
<select class="dropdownlist" required oninvalid="this.setCustomValidity('Please select Accused Name')" onchange="setCustomValidity('')">
function setCustomValidity()
{
var item= document.getElementByClassName('dropdownlist');
var itemvalue= item.options[item.selectedIndex].text;
....
....
}
Hope this help you!
Upvotes: 5
Reputation: 17366
Simply No, not valid for the select
The oninput()
is useful if you want to detect when the contents of a textarea
, input:text
, input:password
or input:search
element have changed, because the onchange
event on these elements fires when the element loses focus, not immediately after the modification.
So, use onchange()
as an alternative for the same!
Hope this will help
Upvotes: 10