Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick script to autofill a simple form.
$(function() {
// autofill();
$('.autofill').click(function(e) {
e.preventDefault();
autofill();
});
});
var makeName = function() {
var firstnames = ["Harry","Oliver","Jack","Charlie","Jacob",
"Thomas","Alfie","Riley","William","James",
"Amelia","Olivia","Jessica","Emily","Lily",
"Ava","Isla","Sophie","Mia","Isabella"];
var lastnames = ["Walker","Jones","Taylor","Brown","Williams",
"Wilson","Johnson","Davies","Robinson","Wright",
"Thompson","Evans","Smith","White","Roberts",
"Green","Hall","Wood","Jackson","Clarke"];
var i = firstnames[Math.floor(Math.random() * firstnames.length)];
var j = lastnames[Math.floor(Math.random() * lastnames.length)];
return i+" "+j;
};
var makeUsername = function() {
var words = ["dreadful", "flooring","turgid","bottom","climb","nuts","cry","strapping",
"choir","playing","worship","roasted","numerous","snapping","light","wig","frazzled",
"bin","grazed","club","boars","bubble","orange","dye","kits","spots","cake","carpal","sulphur",
"apple","scattered","gym","skulk","chaffinch","ubiquitous","slug","cavalcade","jam",
"bony","antelope","foul","illusion","can","chivalrous","green","footed","nut"];
var i = words[Math.floor(Math.random() * words.length)];
var j = words[Math.floor(Math.random() * words.length)];
return i == j ? makeUsername() : i+j;
};
var autofill = function() {
$('#entry-name').val(makeName);
$('#entry-username').val(makeUsername);
var type = Math.random() > 0.5 ? 'twitter' : 'facebook';
$('#entry-type-'+type).prop('checked', true);
var w = Math.floor((Math.random()*1200)+400);
var h = Math.floor((Math.random()*1200)+400);
$('#entry-image').val('http://www.fillmurray.com/'+w+'/'+h);
var descAmount = Math.floor((Math.random()*20)+30);
var desc = $.getJSON('http://json-lipsum.appspot.com/?amount='+descAmount+'&what=words&start=no&callback=?', function(r) {
$('#entry-description').text(r.lipsum);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment