Skip to content

Instantly share code, notes, and snippets.

@jsatk
Forked from adactio/placeholderFromDatalist.js
Last active December 31, 2015 02:09
Show Gist options
  • Save jsatk/7919065 to your computer and use it in GitHub Desktop.
Save jsatk/7919065 to your computer and use it in GitHub Desktop.
(function () {
'use strict';
var doc = this.document,
i, inputs, input, options, rand;
if (!doc.querySelectorAll) return;
inputs = doc.querySelectorAll('input[list]');
for (i = inputs.length - 1; i >= 0; i--) {
input = inputs[i];
options = doc.getElementById(input.getAttribute('list')).getElementsByTagName('option');
rand = Math.floor(Math.random() * options.length);
input.setAttribute('placeholder', options[rand].getAttribute('value'));
}
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment