Skip to content

Instantly share code, notes, and snippets.

@misterdai
Created July 31, 2012 14:44
Show Gist options
  • Save misterdai/3217514 to your computer and use it in GitHub Desktop.
Save misterdai/3217514 to your computer and use it in GitHub Desktop.
Form filler
$('input[type=text],textarea').each(function() {$(this).val(Math.random().toString(36).substring(3))});
$('select').each(function() {
var el = this;
if (el.multiple) {
$('option', el).each(function() {
this.selected = (Math.random() > 0.5);
});
} else {
el.selectedIndex = Math.floor(1 + Math.random() * (el.options.length - 1));
}
});
var radioNames = {};
var radios = $(':radio').each(function() {radioNames[this.name] = true});
for (name in radioNames) {
group = radios.filter('[name=' + name + ']');
radio = $(group[Math.floor(Math.random() * group.length)]);
radio.prop('checked', true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment