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

Creating a form that will change the number of fields based on user input

P: n/a
Hi,

I have a form that collects information about up to 5 items. I would
like the user to be able to select from a drop down menu how many items
for which they want to compare information, and then have the form
change the number of input fields accordingly.

In other words, if the user selects enter info for 3 items, then input
fields for only 3 items are shown, if they change it to 4 items, then a
fourth column shows up in the table with the appropriate input fields.

Any advice that could be provided would be greatly appreciated.

Best wishes,

George Hadley
gh********@yahoo.com

Jan 4 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
wrote on 04 jan 2006 in comp.lang.javascript:
I have a form that collects information about up to 5 items. I would
like the user to be able to select from a drop down menu how many items
for which they want to compare information, and then have the form
change the number of input fields accordingly.

In other words, if the user selects enter info for 3 items, then input
fields for only 3 items are shown, if they change it to 4 items, then a
fourth column shows up in the table with the appropriate input fields.

Any advice that could be provided would be greatly appreciated.


Show us what you have come up with sofar.

Tip:
You can make
<input style='display:none;' id='v1'>
appear with:
n=1
document.getElementById('v'+n).style.display=''

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 4 '06 #2

P: n/a
U can add the text fields dynamically.

addToDiv(div,n) {
var str = "<input type='text' id='textGrp'>";
for(i=0;i<n;i++) {
div.innerHTML += str;
}
}

Call this function after selecting a value in select box.
you can pass div or any other object...something like this.,

onSelectBoxChange() {
var noOfItems;
//get the noOfItems selected.
var myDiv = document.getElementById("divToWhichToAddTextFields ");
addToDiv(myDiv,noOfItems);
}

At server side you can get array of values for parameter ''textGrp''

--Sunil

Jan 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.