Skip to content

Instantly share code, notes, and snippets.

@miwebguy
Last active September 17, 2024 19:10
Show Gist options
  • Save miwebguy/36a67cfa1cc31920e22cf244488535bd to your computer and use it in GitHub Desktop.
Save miwebguy/36a67cfa1cc31920e22cf244488535bd to your computer and use it in GitHub Desktop.
Datalist Check final value against list optoins
<html>
<head>
<script>
function peopleCheck(el)
{
var options = el.list.options;
for (var i = 0; i< options.length; i++) {
if (el.value == options[i].value)
//option matches: work is done
return;
}
//no match was found: reset the value
el.value = "";
var elid = el.getAttribute('id');
el.reportValidity();
return false;
}
<script>
</head>
<body>
<label for='User'>This User</label>
<input type='text' list='people' id='User' name="user"
title='Valid UserName required'
required='true'
autocomplete='off'
onblur="peopleCheck(this); "/>
<datalist id='people'>
<option value='duser'>Diagnostic User</option>
</datalist>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment