I have an HTML form with a datalist and where the value is set with PHP, like
\">
Another option, based on the proposed solution, that preserves the previous value or the new one chosen.
// Global variable to store current value
var oldValue = '';
// Blank value when click to activate all options
$('input').on('click', function() {
oldValue = $(this).val();
$(this).val('');
});
// Restore current value after click
$('input').on('mouseleave', function() {
if ($(this).val() == '') {
$(this).val(oldValue);
}
});
https://jsfiddle.net/jpussacq/7Ldbc013/