Skip to content

Instantly share code, notes, and snippets.

@jonkemp
Created April 5, 2011 15:11
Show Gist options
  • Save jonkemp/903803 to your computer and use it in GitHub Desktop.
Save jonkemp/903803 to your computer and use it in GitHub Desktop.
Pre-populate your forms with random data. For testing forms. Requires jQuery. Includes a bookmarklet.
<!-- include jQuery -->
<script>
$('form').find('input:text').val( function(i, val) {
return $(this).attr('name');
});
$('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');
</script>
<!-- bookmarklet includes jQuery -->
<p><a href="javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement('script');c.type='text/javascript';c.src='http://ajax.googleapis.com/ajax/libs/jquery/'+g+'/jquery.min.js';c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=='loaded'||d=='complete')){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,'1',function($,L){$('form').find('input:text').val(function(i,val){return%20$(this).attr('name');});$('form').find('select').each(function(a){$(this).find('option').each(function(b){if($(this).val()!==''){$(this).parent().val($(this).val());return%20false;}});});$('form').find('input:checkbox, input:radio').attr('checked','checked');});">Populate Forms</a></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment