Do you have an example of this in place? It sounds awesome. 

-----Original Message-----
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of [EMAIL PROTECTED]
Sent: Friday, June 15, 2007 3:25 PM
To: jQuery (English)
Subject: [jQuery] Printer Friendly Form Field Replacements


I have a project that I am working on where I needed to give a printer-
friendly view of a form.  Normally, I would do this server side, but this
form was pretty complicated, had a lot of fields, and I didn't want to do
all the if/then statements that would have been required in my template.
So, Jquery to the rescue.  The snippet below takes the value from each form
field element, replaces it with a paragraph tag with the field's value.  I
have not thoroughly tested and this may not be comprehensive, but I hope it
is useful.  Maybe the form plugin has this kind of functionality already?

 function formFieldsPrinterFriendly() {

    $("[EMAIL PROTECTED], textarea, select").each(function(i){
        if( this.type == 'textarea' ) {
            var input_text = $(this).text();
        } else if ( this.type == 'select-one' || this.type == 'select-
multiple' ) {
            var to_join = new Array();

            $(this).find('[EMAIL PROTECTED]').each(function(){
                to_join.push($(this).text());
            });

            var input_text = to_join.join('<br />');
        } else {
            var input_text = $(this).val();
        }
        $(this).after('<p class="pinput">' + input_text + "</
p>").hide();
    });
}


Reply via email to