SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: Dynamic form
-
Nov 30, 2003, 04:27 #1
- Join Date
- Oct 2000
- Posts
- 407
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Dynamic form
I have been looking at the dynamic form script on (http://javascript.about.com/library/...ldynoforms.htm). It's good and nearly solves my problem but I want to add to it so that there are five new different form input boxes each time I press 'Add Item'.
Can anyone help me out? Also, I am stumped as to how to read values from an array form element using php? I pass the values of this script into php which uses $_POST to extract the form values but all I get is 'multifield' = 'whatever the last value entered was' - where are the other values?
I tried changing this line in the script:
Code:htmlStr += 'Item #' + (i+1) + ' <input type="text" name="multifield" value="' + gFieldValues[i] + '"><br>';
Code:htmlStr += 'Item #' + (i+1) + ' <input type="text" name="multifield[]" value="' + gFieldValues[i] + '"><br>';
-
Nov 30, 2003, 07:44 #2Code:
<SCRIPT LANGUAGE="JavaScript"> <!-- window.onload=function test(){ mul=document.getElementsByName("multifield[]"); for(i=0;i<mul.length;i++) alert(mul[i].value); } //--> </SCRIPT> <INPUT TYPE="text" NAME="multifield[]" value="aaa"> <INPUT TYPE="text" NAME="multifield[]" value="bbb"> <INPUT TYPE="text" NAME="multifield[]" value="ccc">
-
Dec 1, 2003, 16:48 #3
- Join Date
- Oct 2000
- Posts
- 407
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I'm sorry, but I don't understand that. Is it supposed to help with adding more than one input field or is it meant to help read them back?
-
Dec 3, 2003, 05:19 #4
- Join Date
- Oct 2003
- Location
- North Wales
- Posts
- 154
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
To display extra form fields, amend the //Create the new field section of the code to this:
Code:// Create the new field gFieldValues[gFieldValues.length]=""; gFieldValues[gFieldValues.length]=""; gFieldValues[gFieldValues.length]=""; gFieldValues[gFieldValues.length]=""; UpdateForm(); } function UpdateForm() { var htmlStr = GetFormHTML(); if (IE4plus) { document.all.formlayer.innerHTML = htmlStr; } else if (NS4) { document.formlayer.document.open(); document.formlayer.document.write(htmlStr); document.formlayer.document.close(); } else if (NS6) { document.getElementById("formlayer").innerHTML = htmlStr; } }
Hope this helps.
-
Dec 3, 2003, 08:17 #5
- Join Date
- Oct 2000
- Posts
- 407
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks
But then the input fields end up having the same name, don't they? What if I want the input fields to have different names? Like, each time the button is pressed, a field with the name "Address" and a field with the name "City" is added.
Bookmarks