Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

add element into one of two forms by appendTo

i have 2 forms in one page.

When i add element (text field) with appendTo , this element is inserted in both forms

How can i fix it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My current code:

<h4>Example</h4>
<form id="aaa">
   <input  name="test1" value="1">
   <button type="submit">Save</button>
</form>
<form id="bbb">
   <input name="test2" value="2">
   <button type="submit">Send</button>
</form>

And javascript:

$('<input>').attr({ id: 'test-value', name: 'test-value' }).appendTo('form'); $('#test-value').val('demo demo text')

Image

Link : http://jsfiddle.net/bvotcode/zq5rs0tp/20/

Please help

I only want to add element to form with id ="aaa".

>Solution :

$('<input>').attr({ id: 'test-value', name: 'test-value' }).appendTo('form#aaa')

Try this

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading