Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Extracting the values of all forms on the page (See related posts)

This is a simple piece of javascript intended to be run from Firebug or as a bookmarklet which extracts all the name : value pairs from forms on the page and pops up a new window listing them.

It's not very well written, and doesn't yet handle any non input form elements, but it will do for now. :-)

var displayWindow = window.open();

function showFormValues(form ) { 
    displayWindow.document.write('Form:');
    displayWindow.document.write(form.name);
    displayWindow.document.write('<br>');

    var formElements = form.getElementsByTagName('input');

    for (var i = 0; i < formElements.length; i++){
        var element = formElements[i];
        
        displayWindow.document.write(element.name + ' :  ' + element.value + ' <br>');}} 

Array.forEach(document.forms, showFormValues);



You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts