Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Predefined text to fill in textboxes
- var textboxTexts = new Array();
- textboxTexts.push("Hey, hey, temme yern't an a'hole yo!");
- textboxTexts.push("I like to spam. But hey, isn't that illegal?");
- textboxTexts.push("See, I don't want to hurt you mo-fo (if you know what I mean).");
- textboxTexts.push("Now pull down your pants and turn back. Make it quick, yo!");
- var emails = new Array();
- var phnos = new Array();
- phnos.push("9876543210");
- // Function to load external script, required to load jQuery
- function loadScript(url, callback)
- {
- var head = document.getElementsByTagName('head')[0];
- var script = document.createElement('script');
- script.type = 'text/javascript';
- script.src = url;
- script.onreadystatechange = callback;
- script.onload = callback;
- head.appendChild(script);
- }
- // Call above function to load jQuery
- loadScript(location.protocol + "//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js", execMyScript);
- // Callback function, executed after loading JQuery
- function execMyScript() {
- var checkboxes = {}, radios = {}, combos = {};
- // Fill textboxes with predefined text, and collect the radios and checkboxes to fill them randomly later
- $.each($('input'), function(key, value) {
- var type = $(value).attr('type');
- if (type == 'text') {
- // Textboxes
- var label = $('label[for=' + $(value).attr('id') + ']').html();
- // Check the label if the textbox is for an email or a mobile no, fill it appropriately
- if (label.indexOf('Email') != -1 || label.indexOf('E-mail') != -1 || label.indexOf('e-mail') != -1 || label.indexOf('email') != -1) {
- var random = Math.floor((Math.random()* emails.length ));
- $(value).val(emails[random]);
- } else if (label.indexOf('Phone') != -1 || label.indexOf('phone') != -1 || label.indexOf('mobile') != -1 || label.indexOf('Mobile') != -1 || label.indexOf('Contact') != -1) {
- var random = Math.floor((Math.random()* phnos.length ));
- $(value).val(phnos[random]);
- } else {
- var random = Math.floor((Math.random()* textboxTexts.length ));
- $(value).val(textboxTexts[random]);
- }
- } else if (type == 'radio') {
- // Radio buttons, collect them for filling later
- var name = $(value).attr('name');
- var id = $(value).attr('id');
- if (radios[name] !== undefined) {
- radios[name].push(id);
- } else {
- radios[name] = new Array(id);
- }
- } else if (type == 'checkbox') {
- // Checkboxes, collect them for filling later
- var name = $(value).attr('name');
- var id = $(value).attr('id');
- if (checkboxes[name] !== undefined) {
- checkboxes[name].push(id);
- } else {
- checkboxes[name] = new Array(id);
- }
- }
- });
- // Fill collected radios randomly
- $.each(radios, function (key, value) {
- // Generate a random number, and check a radio button
- var random = Math.floor((Math.random()* value.length ));
- $('#' + value[random]).attr('checked', 'checked');
- });
- // Fill collected checkboxes randomly
- $.each(checkboxes, function (key, value) {
- // First generate a random no to decide how many checkboxes to check (for each question)
- var rndcount = Math.floor((Math.random()* value.length ) + 1);
- // Generate that many random numbers and check the checkboxes
- for (var i = 0; i < rndcount; i++) {
- var random = Math.floor((Math.random()* value.length ));
- $('#' + value[random]).attr('checked', 'checked');
- }
- });
- // Fill textareas with textbox text
- $.each($('textarea'), function(key, value) {
- var random = Math.floor((Math.random()* textboxTexts.length ));
- $(value).val(textboxTexts[random]);
- });
- console.log("Filled all I could fill!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement