jQuery AutoForm Script Easy Form AutoComplete

Sam Deering

Tired of filling in web forms? Testing heaps of web forms and keep losing your default values because you have to clear your cookies? Well do I have a treat for you! I have written this jQuery script called jQuery AutoForm and what it does is simple – it auto fills your web forms for you. It works on any forms, signup forms, registration forms, contact forms, basically any browser based form. Good for repetitive form testing saving you heaps of developing time. As most forms have different names such as “name”, “fullname”, “full-name” etc… it can handle this and is fully customisable for every type of form fields.

jQuery AutoForm Features

  • Fast – Fills forms in under 1 second
  • Stable – Works on any browser
  • Accessible – Can take the form of a browser bookmark for easy use
  • Customisable – You can add inputs with any name/any value.
  • Smart – Dates do not expire, it auto populates the date to the current date.

jQuery AutoForm Demo

This is a form containing some standard fields.













Create your own AutoForm

  1. Download JQUERY4U.UTIL.autoForm.js
  2. Customise your name, email and other form fields
  3. Edit the input field names to match specific forms
  4. Obfuscate (optional but nice)
  5. Prepend ‘javascript:’ to your obfuscated code and create a new bookmark
  6. Visit a form and simply click the bookmark

jQuery AutoForm Full Script

(function($) {
 
;var JQUERY4U = {};
 
;JQUERY4U.UTIL =
{
 
    name: 'JQUERY4U.UTIL',
 
    autoForm: function ()
    {
        /* field values fill forms */
        var formValues  = [];
        formValues['firstname'] = 'jQuery';
        formValues['middlename'] = '4u';
        formValues['lastname'] = 'Blog';
        formValues['mobile'] = '0416425699';
        formValues['email'] = 'email@domain.com';
        formValues['house'] = '123';
        formValues['street'] = 'Bank Street';
        formValues['city'] = 'Sunnybank';  
        formValues['country'] = 'Australia';
        formValues['postcode'] = '4109';
        formValues['message'] = 'This is the demo example of jQuery AutoForm.';
        formValues['emailnewsletter'] = true;
     
        /* field name mappings */
        formValues['newsletter'] = formValues['emailnewsletter'];
        formValues['housenumber'] = formValues['house'];
        formValues['name'] = formValues['firstname'] + ' ' + formValues['middlename'] + ' ' + formValues['lastname'];
        formValues['fullname'] = formValues['name'];
        formValues['phone'] = formValues['mobile'];
        formValues['suburb'] = formValues['city'];
        formValues['address1'] = formValues['housenumber'] + ' ' + formValues['street'];
        formValues['address2'] = formValues['suburb'];
        formValues['address3'] = formValues['country'] + ' ' + formValues['postcode'];
        /* enter more field mappings here */

        /* date functions */
        function twodigits(digits) {
            return (digits > 9) ? digits : '0' + digits;
        }
        var fullDate = new Date();
        var twoDigitDays = twodigits(fullDate.getDate());
        var twoDigitMonth = twodigits(fullDate.getMonth() + 1);
        var date = twoDigitDays + "/" + twoDigitMonth + "/" + fullDate.getFullYear();
        fullDate.setDate(fullDate.getDate()+7);
        formValues['date'] = date;  
     
        /*serialize every input field on page */
        var fields = $("input, select, textarea").serializeArray();
     
        /* init - special input type fixes */
        $('input[type=checkbox], input[type=radio]').attr('checked', true);
     
        jQuery.each(fields, function(i, field){
            /* check if field has a value in array */
            if (formValues[field.name] !== 'undefined') {
                $('input[name='+field.name+']').val(formValues[field.name]); /* generic inputs */
                $('textarea[name='+field.name+']').val(formValues[field.name]); /* textarea */
                $('select[name='+field.name+']').attr('selectedIndex', 1); /* select */
                $('input[name='+field.name+']').attr('checked', formValues[field.name]); /* checkbox/radio */
            }
        });
    }
};
JQUERY4U.UTIL.autoForm();
 
})(jQuery);

jQuery AutoForm Script (bookmark obfuscated minified version)

When your finished any customisations of auto populated field names your final script should look something like the code below. To convert this into a bookmark simple prepend “javascript:”.

var _0xdd45=["x55x54x49x4C","x4Ax51x55x45x52x59x34x55x2Ex55x54x49x4C","x66x69x72x73x74x6Ex61x6Dx65","x6Ax51x75x65x72x79","x6Dx69x64x64x6Cx65x6Ex61x6Dx65","x34x75","x6Cx61x73x74x6Ex61x6Dx65","x42x6Cx6Fx67","x6Dx6Fx62x69x6Cx65","x30x34x31x36x34x32x35x36x39x39","x65x6Dx61x69x6C","x65x6Dx61x69x6Cx40x64x6Fx6Dx61x69x6Ex2Ex63x6Fx6D","x68x6Fx75x73x65","x31x32x33","x73x74x72x65x65x74","x42x61x6Ex6Bx20x53x74x72x65x65x74","x63x69x74x79","x53x75x6Ex6Ex79x62x61x6Ex6B","x63x6Fx75x6Ex74x72x79","x41x75x73x74x72x61x6Cx69x61","x70x6Fx73x74x63x6Fx64x65","x34x31x30x39","x6Dx65x73x73x61x67x65","x54x68x69x73x20x69x73x20x74x68x65x20x64x65x6Dx6Fx20x65x78x61x6Dx70x6Cx65x20x6Fx66x20x6Ax51x75x65x72x79x20x41x75x74x6Fx46x6Fx72x6Dx2E","x65x6Dx61x69x6Cx6Ex65x77x73x6Cx65x74x74x65x72","x6Ex65x77x73x6Cx65x74x74x65x72","x68x6Fx75x73x65x6Ex75x6Dx62x65x72","x6Ex61x6Dx65","x20","x66x75x6Cx6Cx6Ex61x6Dx65","x70x68x6Fx6Ex65","x73x75x62x75x72x62","x61x64x64x72x65x73x73x31","x61x64x64x72x65x73x73x32","x61x64x64x72x65x73x73x33","x30","x67x65x74x44x61x74x65","x67x65x74x4Dx6Fx6Ex74x68","x2F","x67x65x74x46x75x6Cx6Cx59x65x61x72","x73x65x74x44x61x74x65","x64x61x74x65","x73x65x72x69x61x6Cx69x7Ax65x41x72x72x61x79","x69x6Ex70x75x74x2Cx20x73x65x6Cx65x63x74x2Cx20x74x65x78x74x61x72x65x61","x63x68x65x63x6Bx65x64","x61x74x74x72","x69x6Ex70x75x74x5Bx74x79x70x65x3Dx63x68x65x63x6Bx62x6Fx78x5Dx2Cx20x69x6Ex70x75x74x5Bx74x79x70x65x3Dx72x61x64x69x6Fx5D","x75x6Ex64x65x66x69x6Ex65x64","x76x61x6C","x69x6Ex70x75x74x5Bx6Ex61x6Dx65x3D","x5D","x74x65x78x74x61x72x65x61x5Bx6Ex61x6Dx65x3D","x73x65x6Cx65x63x74x65x64x49x6Ex64x65x78","x73x65x6Cx65x63x74x5Bx6Ex61x6Dx65x3D","x65x61x63x68","x61x75x74x6Fx46x6Fx72x6D"];(function (_0x65dfx1){;;var _0x65dfx2={};;;_0x65dfx2[_0xdd45[0]]={name:_0xdd45[1],autoForm:function (){var _0x65dfx3=[];_0x65dfx3[_0xdd45[2]]=_0xdd45[3];_0x65dfx3[_0xdd45[4]]=_0xdd45[5];_0x65dfx3[_0xdd45[6]]=_0xdd45[7];_0x65dfx3[_0xdd45[8]]=_0xdd45[9];_0x65dfx3[_0xdd45[10]]=_0xdd45[11];_0x65dfx3[_0xdd45[12]]=_0xdd45[13];_0x65dfx3[_0xdd45[14]]=_0xdd45[15];_0x65dfx3[_0xdd45[16]]=_0xdd45[17];_0x65dfx3[_0xdd45[18]]=_0xdd45[19];_0x65dfx3[_0xdd45[20]]=_0xdd45[21];_0x65dfx3[_0xdd45[22]]=_0xdd45[23];_0x65dfx3[_0xdd45[24]]=true;_0x65dfx3[_0xdd45[25]]=_0x65dfx3[_0xdd45[24]];_0x65dfx3[_0xdd45[26]]=_0x65dfx3[_0xdd45[12]];_0x65dfx3[_0xdd45[27]]=_0x65dfx3[_0xdd45[2]]+_0xdd45[28]+_0x65dfx3[_0xdd45[4]]+_0xdd45[28]+_0x65dfx3[_0xdd45[6]];_0x65dfx3[_0xdd45[29]]=_0x65dfx3[_0xdd45[27]];_0x65dfx3[_0xdd45[30]]=_0x65dfx3[_0xdd45[8]];_0x65dfx3[_0xdd45[31]]=_0x65dfx3[_0xdd45[16]];_0x65dfx3[_0xdd45[32]]=_0x65dfx3[_0xdd45[26]]+_0xdd45[28]+_0x65dfx3[_0xdd45[14]];_0x65dfx3[_0xdd45[33]]=_0x65dfx3[_0xdd45[31]];_0x65dfx3[_0xdd45[34]]=_0x65dfx3[_0xdd45[18]]+_0xdd45[28]+_0x65dfx3[_0xdd45[20]];function _0x65dfx4(_0x65dfx5){return (_0x65dfx5>9)?_0x65dfx5:_0xdd45[35]+_0x65dfx5;} ;var _0x65dfx6= new Date();var _0x65dfx7=_0x65dfx4(_0x65dfx6[_0xdd45[36]]());var _0x65dfx8=_0x65dfx4(_0x65dfx6[_0xdd45[37]]()+1);var _0x65dfx9=_0x65dfx7+_0xdd45[38]+_0x65dfx8+_0xdd45[38]+_0x65dfx6[_0xdd45[39]]();_0x65dfx6[_0xdd45[40]](_0x65dfx6[_0xdd45[36]]()+7);_0x65dfx3[_0xdd45[41]]=_0x65dfx9;var _0x65dfxa=_0x65dfx1(_0xdd45[43])[_0xdd45[42]]();_0x65dfx1(_0xdd45[46])[_0xdd45[45]](_0xdd45[44],true);jQuery[_0xdd45[54]](_0x65dfxa,function (_0x65dfxb,_0x65dfxc){if(_0x65dfx3[_0x65dfxc[_0xdd45[27]]]!==_0xdd45[47]){_0x65dfx1(_0xdd45[49]+_0x65dfxc[_0xdd45[27]]+_0xdd45[50])[_0xdd45[48]](_0x65dfx3[_0x65dfxc[_0xdd45[27]]]);_0x65dfx1(_0xdd45[51]+_0x65dfxc[_0xdd45[27]]+_0xdd45[50])[_0xdd45[48]](_0x65dfx3[_0x65dfxc[_0xdd45[27]]]);_0x65dfx1(_0xdd45[53]+_0x65dfxc[_0xdd45[27]]+_0xdd45[50])[_0xdd45[45]](_0xdd45[52],1);_0x65dfx1(_0xdd45[49]+_0x65dfxc[_0xdd45[27]]+_0xdd45[50])[_0xdd45[45]](_0xdd45[44],_0x65dfx3[_0x65dfxc[_0xdd45[27]]]);} ;} );} };_0x65dfx2[_0xdd45[0]][_0xdd45[55]]();} )(jQuery);
[/cc]

Further Notes

  • Will not work on iFrame embedded forms or popup windows.
  • Will only fill in fields with “name” attributes.
  • Dates do not expire – it auto populates the date to the current date.

Win an Annual Membership to Learnable,

SitePoint's Learning Platform