-
-
Save stivenson/b4e65eddc6d14afecfc32a47591db6c8 to your computer and use it in GitHub Desktop.
Fill your forms with random data. For testing forms. Requires jQuery.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$( function() { | |
$('form').find('input:text').val( function(i, val) { | |
return randomText(); | |
}); | |
$('form').find('input[type="number"]').val( function(i, val) { | |
return randomInt(); | |
}); | |
$('form').find('select').each( function(a) { | |
$(this).find('option').each( function(b) { | |
if ( $(this).val() !== '' ) { | |
$(this).parent().val( $(this).val() ); | |
return false; | |
} | |
}); | |
}); | |
$('form').find('input:checkbox, input:radio').attr('checked', 'checked'); | |
$('form').find('textarea').val( function(i, val) { | |
return randomText() +' '+ randomText() +' '+ randomText() +' '+ randomText(); | |
}); | |
function randomText(){ | |
var text = ""; | |
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
for( var i=0; i < 5; i++ ) | |
text += possible.charAt(Math.floor(Math.random() * possible.length)); | |
return text; | |
} | |
function randomInt(){ | |
var rn1 = Math.floor((Math.random() * 9) + 1); | |
var rn2 = Math.floor((Math.random() * 9) + 1); | |
var rn3 = Math.floor((Math.random() * 9) + 1); | |
var rn4 = Math.floor((Math.random() * 9) + 1); | |
return (rn1*100) + (rn2*100) + (rn3*100) + (rn4*100); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment