Click to See Complete Forum and Search --> : gwetting form field names from an array


azz
04-09-2003, 11:32 AM
hey,

I have a very simple form that reads in three values and passes them to an ASP form handler. I want this ASP page to iterate through an array and use the values from the array to call the specific values from the form. ie:
<body>

<%

var formList = new Array();

formList[0] = 'fname'
formList[1] = 'mname'
formList[2] = 'sname'

var fullname=''

for (i=0; i<=formList.length; i++)
{ fieldName = formList[i];
val=Request.Form(fieldName);
fullname = fullname + val + ' ' }


Response.Write('Hello '+ fullname);


%>


<body>


When I run this, I get told that the Request.Form command is expecting a string value. Don't know if this is a specific limitation of the Request.Form command, but is there a way around this problem?

May look simple, but it will eventually need to handle an array of 50 or so field names and it would be good if iI could use the loop way of doing things.

Any ideas?

Cheers

Azz

SeGamysa
04-09-2003, 01:58 PM
this might be a stupid question but why r u trying this with the
<% %> when the program looks like it belongs in javascript?

azz
04-10-2003, 01:40 AM
Thanks Dave,

Yeah, you're right - it is JScript (or javascript - I just write javascript until it tells me otherwise! LOL)

it *is* valid to use a variable name as the argument to that method.

So I can use a variable name - any ideas why this script may not be working then?

Cheers

Azz

azz
04-10-2003, 03:48 AM
right here it is ...


for (i=0; i<=formList.length; i++)

should read

for (i=0; i<formList.length; i++)

that now works ... tried to iterate beyonf the length of the array.

stoooooopid! :eek:

Thanks for ther help anyway!

SeGamysa
04-10-2003, 08:22 AM
Originally posted by Dave Clark
Not stupid, just uninformed -- but that's ok, here's your thing to learn for the day. It looks like JavaScript because I presume that it is ASP/JScript. ASP does come in the usual flavor of ASP/VBScript (as you know), but it also comes in two other flavors, too: ASP/PerlScript and ASP/Python.

Dave
lol kewl

azz
04-10-2003, 08:25 AM
OK - the basted is finally working!!!

Check it out at:

http://www.tntmagazine.com/uk/newHomePageSet/tguide/travelChoice.asp?guideId=packing

Pretty cool if I may say so myself!

Thanks for all the help, guys!

Cheers

Azz