Click to See Complete Forum and Search --> : How to request an unknown number of variables


telmessos
08-27-2007, 03:16 AM
Hi all,

I have a form and there are three drop down menus (adults, children, infants) which has the values from 0 to 10. My javascript code adds new text fields to the form when the drop down menu changes.
For Example:
Selected option is 0. When the client changes adults drop down to 2, children drop down to 1 and infants drop down to 1, I want the code add
<input type="text" name="adult1" /><br>
<input type="text" name="adult2" /><br>
<input type="text" name="child1" /><br>
<input type="text" name="inf1" /><br>
to the HTML.

So the number of variables are different. We get the number of adults, children, infants from the drop down menu values and text field names goes like adult1,2,3,4

How can I get these values to separate variables? Can anyone send an example code?


Thanks
Ceyhun

Chikara
08-28-2007, 04:01 PM
This is more of a javascript question rather than ASP.

Basically you would need to set a method that writes information to the page when the drop downs change.

onchange="writeNodes();"

When you simply have a while statement in your javascript and keep writing out what you need. NOTE THIS IS PSEUDO CODE AND WILL NOT WORK.

var i = 0;
while i > totalAdult
{

document.writeln('<input type="text" name="adult'+ i + '" /><br />');
i++;
}

telmessos
08-29-2007, 03:05 AM
no you misunderstood me. I already have the javascript on the form file. if you choose 3 on the adults drop down menu. my javascript code creates text fields with the names of adults1, adults2, adults3. The form sends the values of

3 (the number of adults)
adults1
adults2
adults3

I want my ASP code put those values to the variables named adults1 adults2 adults3 automatically. If the form sends 4 as a number of adults, I want my code create 4 variables etc...