JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 25th, 2012, 09:10 PM
hiyatran hiyatran is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2010
Posts: 45 hiyatran User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 56 m 26 sec
Reputation Power: 3
Creating a Form

When I click on an "Add" button, it would create a new form with the "First Name", "Last Name" field and 2 textboxes, just like the original.
So if I click on the "Add" button 5 times, it would create 5 new forms for me. Same idea applies for the "Delete" button.

Here's my code:
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
   <FORM NAME="myForm" id="facebookAcc" onsubmit="return false">
   First Name: <input type="text" name="1stName" ><br />
   Last Name: <input type="text" name="lastName" ><br /><br />
   <input id="bu_add" type="button" value="Add" >
   <input id="bu_delete" type="button" value="Delete">
   </FORM>
</body>
</html>



If you can help me out, I would greatly appreciated. Or if you know what this is call, I can just look it up.

tks
__________________
OutingsForLess.com

Reply With Quote
  #2  
Old October 28th, 2012, 02:26 PM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 599 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 12 h 40 m
Reputation Power: 69
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>

<script>

var formCount = 1;

function newForms()
{
formCount++;
var newform = document.createElement("form");
var newfield = document.createElement("input");
var newfield2 = document.createElement("input");
var newlabel = document.createTextNode("First Name");
var newlabel2 = document.createTextNode("Last Name");
newform.setAttribute("name","myForm"+formCount);
newform.setAttribute("id","facebookAcc"+formCount);
newform.setAttribute("onsubmit","return false");
newfield.setAttribute("type","text");
newfield.setAttribute("class","txtField");
newfield.setAttribute("name","1stName"+formCount);
newfield2.setAttribute("type","text");
newfield2.setAttribute("class","txtField");
newfield2.setAttribute("name","lastName"+formCount);
if (formCount >= 1) {
document.getElementsByTagName("body")[0].appendChild(newform);
document.getElementsByTagName("form")[formCount-1].appendChild(newlabel);
document.getElementsByTagName("form")[formCount-1].appendChild(newfield);
document.getElementsByTagName("form")[formCount-1].appendChild(newlabel2);
document.getElementsByTagName("form")[formCount-1].appendChild(newfield2);
}
}

function removeForm()
{
if (formCount >= 2) {
formCount--;
var oldform = document.getElementById("facebookAcc"+(formCount+1));
document.getElementsByTagName("body")[0].removeChild(oldform);
}
else {
formCount = 1;
}
}

</script>

<style>
form {
margin-top:25px;
}
form[name=myForm] {
margin-top:0px;
}
.txtField {
display:block;
width:150px;
margin-bottom:5px;
}
</style>

</head>
<body>
   <FORM NAME="myForm" id="facebookAcc" onsubmit="return false">
   First Name: <input class="txtField" type="text" name="1stName"/>
   Last Name: <input class="txtField" type="text" name="lastName"/>
   <input id="bu_add" type="button" value="Add" onclick="newForms()">
   <input id="bu_delete" type="button" value="Delete" onclick="removeForm()">
   </FORM>
</body>
</html>

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Creating a Form

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap