Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced formcontrols.js #56

Open
neodigm opened this issue Mar 12, 2015 · 2 comments
Open

Enhanced formcontrols.js #56

neodigm opened this issue Mar 12, 2015 · 2 comments

Comments

@neodigm
Copy link

neodigm commented Mar 12, 2015

Hi, I've modified the formcontrols.js snippet to create an HTML report via a data URI. Helpful in my case where I needed to share form controls with a team. I also excluded hidden elements.

(function() {

var forms = document.querySelectorAll("form");
var sMU = "

Web form audit

";
sMU += "

";
for (var i = 0, len = forms.length; i < len; i++) {
var tab = [ ];

sMU += "

Form: " + forms[i].id + " " + forms[i].name + "

";
sMU += "";
sMU += "";
sMU += "";
sMU += "";
sMU += "";
sMU += "";
sMU += "";
sMU += "";

console.group("HTMLForm \"" + forms[i].name + "\": " + forms[i].action);
console.log("Element:", forms[i], "\nName:    "+forms[i].name+"\nMethod:  "+forms[i].method.toUpperCase()+"\nAction:  "+forms[i].action || "null");

["input", "textarea", "select"].forEach(function (control) {
  [].forEach.call(forms[i].querySelectorAll(control), function (node) {

if (node.type != "hidden") {
sMU += "

";
sMU += "";
sMU += "";
sMU += "";
sMU += "";
sMU += "";
sMU += "";
}
tab.push({
"Element": node,
"Type": node.type,
"Name": node.name,
"Value": node.value,
"Pretty Value": (isNaN(node.value) || node.value === "" ? node.value : parseFloat(node.value))
});

  });
});

console.table(tab);
console.groupEnd();

sMU += "

IdHTML5 TypeNameValueFormatted
" + node.id + "" + node.type + "" + node.name + "" + node.value + "" + (isNaN(node.value) || node.value === "" ? node.value : parseFloat(node.value)) + "



";
}

window.location.href = "data:text/html;charset=UTF-8,"+sMU;

})();

@neodigm
Copy link
Author

neodigm commented Mar 12, 2015

Wow, that does not read well. Try this: http://codepen.io/neodigm/pen/azRjdG.js

@scouserantro
Copy link

great script - very useful. many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants