-1

I am trying to print a form (no server side involved) by copying the form using $(elem).html(). The problem is that the property values the user enters are not captured. I managed to get around this for input text areas and input check boxes using the answer supplied to my question how do I print a html form along with its contents but I have not been able to do the same for a textarea. Here's the code I used for the text and check box fields.

function CopyElem(elem)
{

   $('form input[type=text]').each(function() {
     $(this).attr('value', $(this).val());
   });

   $('form input[type=checkbox]').each(function() {
     $(this).attr('checked', $(this).prop("checked"));
   });

   $('form textarea').each(function() {

   });

}

So the question is what's needed for the textareas?

Community
  • 1
  • 1
Mike D
  • 2,753
  • 8
  • 44
  • 77
  • 1
    Please check http://stackoverflow.com/questions/415602/set-value-of-textarea-in-jquery – Pugazh Apr 06 '15 at 13:54
  • Text area doesn't have value attribute. This might help you `$('form textarea').text(function() { return $(this).val(); });` – Satpal Apr 06 '15 at 14:09
  • @Satpal Since when does ` – DevlshOne Apr 06 '15 at 14:19
  • @DevlshOne, Really `textarea` has `value` attribute? – Satpal Apr 06 '15 at 14:23
  • `Attribute`, no... but jQuery will get the value every single time. – DevlshOne Apr 06 '15 at 14:29

1 Answers1

-1

Taking a clue from PUGAZH's comment and the question he referenced, I tried

     $(this).html($(this).val());   

and that did the trick. Don't have the least idea if that's the right thing to do but it worked for me.

Mike D
  • 2,753
  • 8
  • 44
  • 77