/    Sign up×
Community /Pin to ProfileBookmark

Dynamica Web Form

I am trying to make a dynamic input form as part of a project. The form needs to be able to create new inputtextareas and selection combobox when an ‘add button’ is pressed and delete them also if necessary. After pressing the add button a <br> must permit a new line to add a new group of input areas.

I have the following code but does not work as needed.

[CODE]
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”>
<html>
<head>
<title>add/subtract textareas</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>

<style type=”text/css”>
<!–
fieldset {
width:395px;
border:3px double #000;
margin:50px auto;
}
legend {
margin-left:10px;
}
#butts {
padding:10px 0 10px 0;
text-align:center;
}
#txtara {
width:385px;
margin:auto;
}
#txtara textarea {
overflow:auto;
margin:5px;
float:left;
}
#clear {
height:10px;
font-size:0;
clear:both;
}
–>
</style>

<script type=”text/javascript”>
<!–
var br=new Array();
var ta=new Array();
var so=new Array();
var so2=new Array();
var n=0;
window.onload=function() {
inp=document.getElementsByTagName(‘input’);
for(c=0;c<inp.length;c++) {
if(inp[c].value==’add’) {
inp[c].onclick=function() {
ta[n]=document.createElement(‘input’);
ta[n].setAttribute(‘rows’,5);
ta[n].setAttribute(‘cols’,20);
ta[n].name=’box’+n;
document.getElementById(‘txtara’).appendChild(ta[n]);
so[n]=document.createElement(‘select’);
so[n].options[0]=new Option(“”, “”, true, false);
so[n].options[1]=new Option(“(“, “(“, false, false);
document.getElementById(‘opt’).appendChild(so[n]);
so2[n]=document.createElement(‘select’);
so2[n].options[0]=new Option(“Fecha de Nacimiento”, “fecha_nac”, true, false);
so2[n].options[1]=new Option(“Nombre”, “nombre”, false, false);
so2[n].options[2]=new Option(“e-Mail”, “email”, false, false);
document.getElementById(‘opt’).appendChild(so2[n]);
br[n]=document.createElement(‘br’);
document.getElementById(‘break’).appendChild(br[n]);
n++;
}
}
if(inp[c].value==’subtract’) {
inp[c].onclick=function() {
if(n<1) {
return;
}
document.getElementById(‘txtara’).removeChild(ta[n-1]);
document.getElementById(‘opt’).removeChild(so[n-1]);
document.getElementById(‘break’).removeChild(br[n-1]);
if(n>0) {
n–;
}
}
}
}
}
//–>
</script>

</head>
<body>

<form action=”http://www.google.com” method=”get”>
<fieldset>

<legend>textareas</legend>

<div id=”butts”>
<input type=”button” value=”add”>
<input type=”button” value=”subtract”>
<input type=”submit” value=”submit”>
</div>

<div id=”opt”></div> <div id=”txtara”></div> <div id=”break”></div>

<div id=”clear”></div>

</fieldset>
</form>

</body>
</html>
[/CODE]

Hope you guys can help me.

Thank you very much.

to post a comment
JavaScript

1 Comments(s)

×

Success!

Help @eamaya spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...