» » Use Jquery to copy form element

 

Use Jquery to copy form element

Author: bamboo06 on 2-04-2016, 16:19, views: 3447

50
When we submit the form, sometimes you encounter the need to repeat the same form to add multiple elements, such as order information you need to add a number of different types of products, form data in the new field information. This time we can put a "new one" or "Copy" button directly on the form, you can achieve copy form elements by clicking on the button.


HTML
In this article we copy a simple plug-in jQuery based elements introduced by way of example, by calling the plug-in element easily copy function.
First, load the jQuery library file and copy the plug element duplicateElement.min.js.
<script src="jquery.js"></script> 
<script src="duplicateElement.min.js"></script> 

We assume that you want to copy user information element, forms html structure is as follows:
<form id="myform" name="myform" action="post.php" method="post">
	<fieldset id="additional">
		<label for="name">Name: </label><input id="name" name="name[]" type="text" class="input" >
		<label for="flag">Level: </label>
		<select id="flag" name="flag[]">
			<option disabled="" selected="">Select</option>
			<option value="1">VIP</option>
			<option value="2">VIP2</option>
		</select>
		&nbsp;
		<a href="javascript:void(0);"  class="btn remove">Remove</a>
		<a href="javascript:void(0);"  class="btn create">Copy</a>
	</fieldset>
	
	<br/>
	<div class="sub_btn">
		<input type="submit" class="button" value="Submit">
	</div>
</form>


jQuery
We click on the "Copy" button, the contents of the #additional copy, the equivalent of a new row, the initial display when only the "copy" button to copy after the original piece will show "Remove" button, click "remove" to remove the corresponding row can be.
    $(function () { 
        $('#additional').duplicateElement({ 
            "class_remove": ".remove", 
            "class_create": ".create", 
            onCreate: function (el) { 
                el.find("select").prop('defaultSelected'); 
                el.find(".input").val(''); 
            } 
        }); 
    }); 

We can also add callback() function to define attributes new form elements after succeeded copying, such as form elements value or style and so on through onCreate.

Category: Javascript

Dear visitor, you are browsing our website as Guest.
We strongly recommend you to register and login to view hidden contents.
<
  • 0 Comments
  • 0 Articles
21 December 2017 21:47

International Business Services

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Words Kshetra is offering international business services for expand business on international business platform with Joint Ventures, L.L.P, Contracts or Franchise support.

<
  • 0 Comments
  • 0 Articles
24 December 2017 21:41

Robinjack

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Much thanks to you for setting aside an ideal opportunity to distribute this data extremely valuable! Outdoor games

<
  • 0 Comments
  • 0 Articles
27 December 2017 23:27

peeter

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
This is truly a decent and useful, containing all data furthermore greatly affects the new innovation. A debt of gratitude is in order for sharing it Invention

<
  • 0 Comments
  • 0 Articles
31 December 2017 18:27

peter

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Awesome article with astounding idea!Thank you for such a significant article. I truly acknowledge for this extraordinary data.. Weight loss

<
  • 0 Comments
  • 0 Articles
2 January 2018 21:42

peter

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Much thanks for the sharing! COOL.. Indoor games

I take in some new stuff from it as well, a debt of gratitude is in order for sharing your data. Software

<
  • 0 Comments
  • 0 Articles
3 January 2018 17:22

Ashar Seo

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
I take in some new stuff from it as well, a debt of gratitude is in order for sharing your data. packers and movers baner

<
  • 0 Comments
  • 0 Articles
5 January 2018 23:12

Kolkata Escorts

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Beauti Queen amazing kolkata escorts agency alwyas ready for you at your doorstep. Beauti Queen provide you high profile independent girl in kolkata, escorts service in kolkata, kolkata escorts. If you are looking for the ultimate encounter in Kolkata then I am your sophisticated young Kolkata escorts that provides upscale companionship for making your night becomes true.
escorts service in kolkata, kolkata escorts, escorts in kolkata, independent escorts in kolkata, female escorts in kolkata

<
  • 0 Comments
  • 0 Articles
8 January 2018 22:57

Celina

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
I felt very happy while reading this site. This was really very informative site for me. I really liked it. This was really a cordial post. Thanks a lot! Voyance par téléphone.

<
  • 0 Comments
  • 0 Articles
10 January 2018 17:01

Robinjack

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Your work is great and I value you and bouncing for some more educational posts. Much obliged to you for sharing incredible data to us. Get Business Today

<
  • 0 Comments
  • 0 Articles
12 January 2018 19:25

peter

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
much obliged this is great web journal.
bestshoppingshop.com

<
  • 0 Comments
  • 0 Articles
20 January 2018 22:33

Robinjack

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
helpful data on points that bounty are intrigued on for this magnificent post.Admiring the time and exertion you put into your b!.. Game tips

Hi. I discovered your web journal utilizing msn. This is a to a great degree elegantly composed article. I will make sure to bookmark it and come back to peruse a greater amount of your valuable data. A debt of gratitude is in order for the post. I"ll surely rebound. Accounting

<
  • 0 Comments
  • 0 Articles
21 January 2018 17:26

Robinjack

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
you are guaranteed to find a great gift matching whatever price range you have. If your budget is £200 you can get an exquisite necklace (see image) and if your budget is £20 then we have some charming pendants. All our prices are very competitive and we try to give you, the customer, as much of a good deal as we can. Silver jewellery is becoming more and more popular as the months go on, and, over the last year Events

<
  • 0 Comments
  • 0 Articles
21 January 2018 21:37

peter

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Amazing site, Distinguished criticism that I can handle. Im pushing ahead and may apply to my present place of employment as a pet sitter, which is exceptionally charming, however I have to extra extend. Respects.
Skin Care

<
  • 0 Comments
  • 0 Articles
29 January 2018 23:25

BachJohann

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
The post is written in very a good manner and it contains many useful information for me. contractor los angeles remodeling

<
  • 0 Comments
  • 0 Articles
1 February 2018 23:17

Kolkata Escorts

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Renu Das Kolkata Escorts Services has gorgeous females provides Independent Escorts Service in Kolkata call girls at 100% satisfaction with VIP models. Provided Kolkata escorts at our agency are professional in nature and are eager to serve you at your place.
kolkata escorts, escorts in kolkata, escorts service in kolkata, female escorts in kolkata, escorts agency in kolkata, independent escorts in kolkata

<
  • 0 Comments
  • 0 Articles
13 February 2018 17:21

BachJohann

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Avignon escort annonces. Des milliers de petites Annonces de Rencontres. Escort girl occasionnelles ou etudiantes escorte Avignon. Numero de telephone escorte girl Avignon. Retrouve les Escort girl sur Avignon. Avignon Escorts

<
  • 0 Comments
  • 0 Articles
17 February 2018 00:17

BachJohann

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
With so many treadmills in the market today making the decision to choose the right treadmill is difficult. Given the amount of mоney spent on a treadmill you need to know which treadmill is right for you so that it does provide you with the long term benefits you are looking for. We, at Unison Fitness, have created a buyers guide to help you in making your decision. best compact treadmills

<
  • 0 Comments
  • 0 Articles
28 February 2018 04:33

Delhi Escorts

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Riya Chaudhary is an Independent Delhi Escort girl, who offers dazzling hot Delhi Escorts Service, incall or outcall services both to complete your dreams in real entertainment. We offers high class Independent Escorts in Delhi at Riya Chaudhary Delhi Escorts service agency for elite peoples in the city to avail ultimate satisfaction. you can spend your beautiful moments.
delhi escorts, independent escorts in delhi, escorts in delhi

Previous Next
Information
Comment on the news site is possible only within (days) days from the date of publication.