Javascript and dynamic form objects

N

NoChat

All --

I'm looking for some Javascript code that will let me select a number
from a drop-down list (1-100) and dynamically generate that number of
form objects for a user to fill out. Basically, it's an order form.
A user will select how many items he or she would like to order, and
then based on that number, the proper number of fields will be
displayed for completion.

Having some trouble figuring out how to do this, any help is greatly
appreciated!
 
L

Lee

NoChat said:
All --

I'm looking for some Javascript code that will let me select a number
from a drop-down list (1-100) and dynamically generate that number of
form objects for a user to fill out. Basically, it's an order form.
A user will select how many items he or she would like to order, and
then based on that number, the proper number of fields will be
displayed for completion.

Having some trouble figuring out how to do this, any help is greatly
appreciated!

Don't forget to consider the case in which the user, after filling
out 100 fields, realizes that they really need 103. Most simple
solutions to this problem will delete everything they've entered.

A better solution might be to design the page so that filling in
one field triggers the creation of the next one.


--
 
N

NoChat

NoChat said:






Don't forget to consider the case in which the user, after filling
out 100 fields, realizes that they really need 103. Most simple
solutions to this problem will delete everything they've entered.

A better solution might be to design the page so that filling in
one field triggers the creation of the next one.

--

Very true. Perhaps I should add a few input boxes for the first item
and offer an "Add Another Item" button at the bottom so the user can
add as he or she needs as opposed to all at once. Anyone have
experience doing this? I found a few scripts on the net, but none
seem to work all that well...
 
D

Doug Gunnoe

All --

I'm looking for some Javascript code that will let me select a number
from a drop-down list (1-100) and dynamically generate that number of
form objects for a user to fill out. Basically, it's an order form.
A user will select how many items he or she would like to order, and
then based on that number, the proper number of fields will be
displayed for completion.

Having some trouble figuring out how to do this, any help is greatly
appreciated!

Here is an example I whipped up. May or may not be what you need.

Good luck!

<html>

<head>
<title>Write text boxes</title>
</head>

<body>

<form>

<select id="numOfTextBoxes" name="numOfTextBoxes"
onChange="writeTextBoxes()">
<option SELECTED value=0>0</option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
</select>

<script>
function writeTextBoxes(){

txtBoxHome = document.getElementById("homeForTextBoxes");
wrTextBxs = document.getElementById("numOfTextBoxes");
n = wrTextBxs.options[wrTextBxs.selectedIndex].value;
htmlString ="";
txtBxName = "txt_box_";


for(i = 0;i<n;i++){
txtBxName = "txt_box_" + i;
htmlString += "<br><input type='text' name='" + txtBxName + "' />";
}

txtBoxHome.innerHTML=htmlString;


}
</script>

<div id="homeForTextBoxes"></div>

</form>


</body>


</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,147
Messages
2,570,833
Members
47,380
Latest member
AlinaBlevi

Latest Threads

Top