/ Published in: JavaScript
I wrote this very quickly for a form I parse that allows a user to send a page to up to 5 friends. The script adds a click event to an image of a + sign beside an input box. When clicked if the user hasn't already added 5 friends to email, additional email boxes will be added.
Expand |
Embed | Plain Text
<script type="text/javascript" charset="utf-8"> $(function() { var fieldCount = 1; $("#addFieldButton").click(function() { fieldCount++; if(fieldCount <= 5) { var fieldID = "recipient_email_" + fieldCount; $("#additionalEmails").append("<label for='"+fieldID+"'>Recipient Email "+fieldCount+": </label>"+ "<input type='text' name='"+fieldID+"' " + "id='"+fieldID+"' size='30'><br />" ); } else { alert("Maximum email fields reached."); } }); }); </script>
Comments
Subscribe to comments
You need to login to post a comment.

I should note, #addFieldButton is the ID for the button that adds the fields. #additionalEmails is the name of the div that gets populated with additional forms.
in above example:
is the dynamic portion.
How can i get id of above input by jquery.
Thanks in advance.. Mahi