Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function add_field(addToo,type)
- {
- switch(type)
- {
- case 'email':
- add_email(addToo);
- break;
- }
- // More case statements will be added later
- }
- function add_email(addToo)
- {
- ++numEmail;
- var container = document.getElementById(addToo);
- // New parent DIV
- var div=document.createElement('div');
- div.id='email_'+numEmail;
- // New input text box
- var txt=document.createElement('input');
- txt.type='text';
- txt.name="email["+numEmail+"]";
- // Select box
- var sel=document.createElement('select');
- var opt1=document.createElement('option');
- var opt2=document.createElement('option');
- var opt3=document.createElement('option');
- sel.name='email_type['+numEmail+']';
- opt1.appendChild(document.createTextNode('Home'));
- opt2.appendChild(document.createTextNode('Work'));
- opt3.appendChild(document.createTextNode('Parent(s)'));
- opt1.value='Home';
- opt2.value='Work';
- opt3.value='Parents';
- sel.appendChild(opt1);
- sel.appendChild(opt2);
- sel.appendChild(opt3);
- // Remove link
- var a=document.createElement('a');
- a.setAttribute('href','#');
- a.setAttribute('onclick', "remove_node('email_"+numEmail+"'); return false;");
- a.appendChild(document.createTextNode('remove'));
- a.style.marginLeft='1.1em';
- div.appendChild(txt);
- div.appendChild(sel);
- div.appendChild(a);
- container.appendChild(div);
- }
- /*
- * Remove a child node from an HTML element.
- * id: the id of the node you wish removed from DOM.
- */
- function remove_node(id)
- {
- var elem=document.getElementById(id);
- elem.parentNode.removeChild(elem);
- }
- <p><a href="" onclick="add_field('emails','email');return false;">Add Email</a></p>
- <div id="emails"></div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement