Skip to content

Instantly share code, notes, and snippets.

@elidickinson
Created October 14, 2011 19:23
Show Gist options
  • Save elidickinson/1288059 to your computer and use it in GitHub Desktop.
Save elidickinson/1288059 to your computer and use it in GitHub Desktop.
form auto fill
javascript:var%20auto%20={names:%20'Steve%20Buscemi%20Catherine%20Keener%20Dermot%20Mulroney%20Danielle%20Zerneck%20James%20LeGros%20Rica%20Martens%20Peter%20Dinklage%20Kevin%20Corrigan%20Hilary%20Gilford%20Robert%20Wightman%20Tom%20Jarmusch%20Michael%20Griffiths%20Matthew%20Grace%20Ryan%20Bowker%20Francesca%20DiMauro',blurb:%20'phpBB%20is%20a%20free,%20open%20source%20Internet%20community%20application,%20with%20outstanding%20discussion%20forums%20and%20membership%20management.%20Written%20in%20the%20PHP%20scripting%20language,%20and%20making%20use%20of%20the%20popular%20MySQL%20database,%20phpBB%20is%20a%20standard%20among%20web%20hosting%20companies%20throughout%20the%20world,%20and%20is%20one%20of%20the%20most%20widely-used%20bulletin%20board%20packages%20in%20the%20world.%20phpBB%20short-circuits%20the%20need%20for%20you%20to%20be%20a%20web%20development%20master%20in%20order%20to%20create%20and%20manage%20massive%20online%20communities',password:%20'secret',fillerup:%20function()%20{var%20all_inputs%20=%20document.getElementsByTagName('input');var%20all_selects%20=%20document.getElementsByTagName('select');var%20all_textareas%20=%20document.getElementsByTagName('textarea');for%20(var%20i%20=%200,%20max%20=%20all_selects.length;%20i%20<%20max;%20i++)%20{var%20sel%20=%20all_selects[i];%20if%20(sel.selectedIndex%20!=%20-1&&%20sel.options[sel.selectedIndex].value!=0)%20{continue;%20}var%20howmany%20=%201;%20if%20(sel.type%20==%20'select-multiple')%20{%20var%20howmany%20=%201%20+%20this.getRand(sel.options.length%20-%201);}for%20(var%20j%20=%200;%20j%20<%20howmany;%20j++)%20{var%20index%20=%20this.getRand(sel.options.length%20-%201);sel.options[index].selected%20=%20'selected';}}for%20(var%20i%20=%200,%20max%20=%20all_textareas.length;%20i%20<%20max;%20i++)%20{var%20ta%20=%20all_textareas[i];if%20(!ta.value)%20{ta.value%20=%20this.getRandomString(10)+%20'\n\n'+%20this.getRandomString(10);}}for%20(var%20i%20=%200,%20max%20=%20all_inputs.length;%20i%20<%20max;%20i++)%20{var%20inp%20=%20all_inputs[i];var%20type%20=%20inp.getAttribute('type');if%20(!type)%20{type%20=%20'text';%20}if%20(type%20==%20'checkbox')%20{inp.setAttribute('checked',%20'checked');}if%20(type%20==%20'radio')%20{var%20to_update%20=%20true;var%20name%20=%20inp.name;var%20input_array%20=%20inp.form.elements[inp.name];for%20(var%20j%20=%200;%20j%20<%20input_array.length;%20j++)%20{if%20(input_array[j].checked)%20{to_update%20=%20false;continue;}}if%20(to_update)%20{var%20index%20=%20this.getRand(input_array.length%20-%201);input_array[index].setAttribute('checked',%20'checked');}}if%20(type%20==%20'password')%20{if%20(!inp.value)%20{inp.value%20=%20this.getPassword();}}if%20(type%20==%20'text')%20{if%20(!inp.value)%20{if%20(inp.name.indexOf('name')%20!=%20-1)%20{inp.value%20=%20this.getRandomName()%20+%20'%20'%20+%20this.getRandomName();}%20else%20if%20(inp.name.indexOf('email')%20!=%20-1)%20{inp.value%20=%20this.getRandomString(1)%20+%20'@example.org';}%20else%20{inp.value%20=%20this.getRandomString(1);}}}}},getRandomString:%20function%20(how_many_words)%20{if%20(!how_many_words)%20{how_many_words%20=%205;}if%20(!this.words)%20{this.words%20=%20this.blurb.split('%20');}var%20retval%20=%20'';for%20(var%20i%20=%200;%20i%20<%20how_many_words;%20i++)%20{retval%20+=%20this.words[this.getRand(this.words.length)%20-%201];retval%20+=%20(i%20<%20how_many_words%20-%201)%20?%20'%20'%20:%20'';}return%20retval;},getRandomName:%20function%20()%20{if%20(!this.split_names)%20{this.split_names%20=%20this.names.split('%20');}return%20this.split_names[this.getRand(this.split_names.length)%20-%201];},getPassword:%20function%20()%20{if%20(!this.password)%20{this.password%20=%20'secret';}return%20this.password;},getRand:%20function%20(count)%20{return%20Math.round(count%20*%20Math.random());}};%20auto.fillerup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment