By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,581 Members | 2,007 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,581 IT Pros & Developers. It's quick & easy.

How to expand the number of fields in a form?

P: n/a
Hi group

I want to be able to expand a huge form with a number of text fields.
The number of fields must be entered in a form field and submitted, or
alternatively be a drop down menu. I have tried both, but none of the
methods succeded. When the submit button is hit a new page enters with
the form inputs, I want them to appear at the end of my form.

I have tried with something like:

<form NAME="formname">
..
..
..
<input TYPE="text" NAME="test">
<input TYPE="BUTTON" VALUE="Press" onclick="show();">

<script type="text/javascript"><!--

function show(){
tmp = document.formname.test.value;
for(i = 1; i <= tmp; i++){
document.write("<input type=\"text\" name=\"save[]\"><br> ");
}
}

//--></script>
</form>

In the drop down menu I tried using "onchange" with same result.

It does not work, does anyone have a suggestion??

Regards
Michael
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In article <c6**********@sunsite.dk>, mp****@control.auc.dk enlightened
us with...
Hi group

I want to be able to expand a huge form with a number of text fields.
The number of fields must be entered in a form field and submitted, or
alternatively be a drop down menu. I have tried both, but none of the
methods succeded. When the submit button is hit a new page enters with
the form inputs, I want them to appear at the end of my form.


Simple example for DOM browsers only:
(tested in NN7/IE6)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> New Document </title>
<script type="text/javascript">
function show(frm)
{
var e;
for (var i=0; i<frm.elements["select_1"].selectedIndex; i++)
{
e = document.createElement("input");
e.setAttribute("type","text");
e.setAttribute("name","text"+i);
document.getElementById("f1").appendChild(e);
}
}
</script>
</head>

<body>
<form name="f1" id="f1">
How many fields? <select name="select_1">
<option value='0'>-- choose one --</option>
<option value='1'>one</option>
<option value='2'>two</option>
<option value='3'>three</option>
<option value='4'>four</option>
<option value='5'>five</option>
</select>
<input type="button" value="Make" onClick="show(this.form)">
</form>
</body>
</html>

--
--
~kaeli~
What, me, normal?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2

P: n/a
Michael Pedersen wrote:
I want to be able to expand a huge form with a number of text fields.


http://www.quirksmode.org/index.html?/dom/domform.html

Andrew Graham
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.