Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How to expand the number of fields in a form?

Reply
Thread Tools

How to expand the number of fields in a form?

 
 
Michael Pedersen
Guest
Posts: n/a
 
      04-22-2004
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
 
Reply With Quote
 
 
 
 
kaeli
Guest
Posts: n/a
 
      04-22-2004
In article <c68sbe$jvm$>, 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

 
Reply With Quote
 
 
 
 
Andrew Graham
Guest
Posts: n/a
 
      04-22-2004
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
epydoc: How to add new fields as the building fields? Cyril.Liu Python 0 12-02-2008 05:01 AM
print struct fields and its member structs' fields recursively, generically call_me_anything C++ 4 09-30-2007 10:12 PM
Expand number of allowable users on Windows 2000 Server Rolf Computer Support 9 08-15-2006 09:27 AM
OT: Number Nine, Number Nine, Number Nine FrisbeeŽ MCSE 37 09-26-2005 04:06 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57