最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - clone html form WITH values - Stack Overflow

programmeradmin2浏览0评论

I am trying to duplicate a form after it has been filled out. So the user fills out the form then hits submit. then a new window opens with the full html form, images, and styling included AND the values so they can print the filled out version. i tried .html() and .clone(). but neither seem to work.

any help is much apperciated. and please don't hesitate to ask questions.

I am trying to duplicate a form after it has been filled out. So the user fills out the form then hits submit. then a new window opens with the full html form, images, and styling included AND the values so they can print the filled out version. i tried .html() and .clone(). but neither seem to work.

any help is much apperciated. and please don't hesitate to ask questions.

Share Improve this question asked Apr 15, 2011 at 12:15 Steve FischerSteve Fischer 3251 gold badge5 silver badges15 bronze badges 3
  • 1 clone() seems to work fine: jsfiddle/fkling/te3LX Maybe you should post your code too. – Felix Kling Commented Apr 15, 2011 at 12:18
  • Correction: It seems only to work for input elements. – Felix Kling Commented Apr 15, 2011 at 12:34
  • ahh ok. bennadel./blog/… i started with this. maybe it will help – Steve Fischer Commented Apr 15, 2011 at 12:36
Add a ment  | 

2 Answers 2

Reset to default 3

Edit: Post your code for creating the popup.

You may need to use val() to copy the values over. http://jsfiddle/Na6GN/2/

$('#myForm :input').each(function() {
    $(this).clone().appendTo('#newForm').val($(this).val());
});

Its working fine:

JS:

$('btnclone').click(function() {
    var mywindow = window.open();
    $(mywindow.document.body).append($('form').eq(0).clone());
});

Html Code

<form>
    <input name='test' />
</form>

<input type="button" value="Clone" name="btnclone" id="btnclone" />
发布评论

评论列表(0)

  1. 暂无评论