Click to See Complete Forum and Search --> : use variable to name form object


mlg0001
02-16-2004, 02:29 PM
I have an ASP page displaying a set of 2 radio buttons represented for each record from a database. One radio button value is "1" the other value is "0".
I want each set of radio buttons to be named based on the values in the database record.

Say for instance the variable is called sServerName. sServerName is the value from the database record.

I have the radio buttons named like this"
<input type="radio" name="<%=sServerName%>" value="1">
<input type="radio" name="<%=sServerName%>" value="0">

If I try to say Request.form("sServerName") - this returns the value of the the radio button - which is "1" or "0".
I want to be able to get the actual name of the radio button.

Is this possible ?

Ribeyed
02-16-2004, 03:17 PM
Hi,
there are 2 ways you can do this. Look at this example:


for each item in request.form(item)
response.write item & " = " & request.form(item)
next


I used response.write in the example you can do what ever you need to do at that point. Now you can't make the variable name dynamic so you have to encapsulate your code for processing the values within the loop.
This method is a bit haywire as there is no way to predict the order of the form elements that are requested. For some reason they don't follow the orginal fllow of your form elements.
A better method would be to use a count:


for x = 0 to request.form.count
response.write request.form(x)
next


You may need to use an if statement to miss out any other form elements that you don't want to be processed they same way are your dynamic elements.

Hope this helps.

buntine
02-16-2004, 11:17 PM
Oops, remember for loops use 'next' rather than 'loop'

Bullschmidt
02-17-2004, 12:58 AM
Also I don't know if this might help at all:

Using the Eval and Execute Functions - 3/3/2000
http://www.4guysfromrolla.com/webtech/030300-1.shtml