Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

request.form(i) is there a 'name' property?

Status
Not open for further replies.

JulianUK

Programmer
Apr 17, 2002
73
GB
Hi

Is there a 'name' property (or the like) when using Request.Form(index)?

i.e. i need to get the name of a particular element by it's index, rather than by it's name. The reason being that I'm iterating through all form elements, but want to ignore those of a certain name.

It's got me stumped anyway.

Many thanks and have a great Christmas.

Julian
 
if you had the following code in an ASP:
[tt]
For Each Foo in Request.Form
Response.Write Foo & " = " & Request.Form(Foo) & " <br>"
Next
[/tt]

it would print a list of all of the request elements and their values...


So by extrapolating a little, we can do what you ask like this:[tt]
For Each Foo in Request.Form
If Foo = "BadValue" Then
Response.Write "We skipped one!<br>"
Else
Response.Write Foo & " = " & Request.Form(Foo) & " <br>"
End if
Next
[/tt]

... just use your own "BadValue" ...
 
<%
For x = 1 to Request.Form.Count
Response.Write Request.Form.Key(x) & " = "
Response.Write Request.Form.Item(x) & "<br>"
Next
%>

-DNG
 
Thanks Sheco, but that wouldn't suit. I'd be checking data values, and for all I know, one of the values I don't know could be "BadValue". Hence I need the actual name of the item.

DNG, exactly what I'm after, and exactly what I found out a few minutes after I posted, but I couldn't post back for some unknown reason, an error with the forum.

Cheers though, and IS there a good online reference for that sort of thing?

Julian
 
JulianUK,

Sheco's example has the same result as DNG's - except with a bit of validation for the name you want to omit. In Sheco's example, Foo would be the name of the value which is then used as the key to the collection. DNG just posted a variant of Shecos approach, which rather than using the named index of the collection gained from iterating using For Each, it uses the numerical index gained from a For incrementor loop.

Hope that clarifies.

Good References for learning ASP:


There are many more, but the best one is: ;-)




A smile is worth a thousand kind words. So smile, it's easy! :)
 
JulianUK,

Sheco's example has the same result as DNG's - except with a bit of validation for the name you want to omit. In Sheco's example, Foo would be the name of the value which is then used as the key to the collection. DNG just posted a variant of Shecos approach, which rather than using the named index of the collection gained from iterating using For Each, it uses the numerical index gained from a For incrementor loop.

Hope that clarifies.

Good References for learning ASP:


There are many more, but the best one is: ;-)


A smile is worth a thousand kind words. So smile, it's easy! :)
 

What IS going on with the site today... ? Posting is almost Random...

A smile is worth a thousand kind words. So smile, it's easy! :)
 
damber...even if you are bored that doesnt mean you have to post it multiple times ;)...

just kidding...i noticed that the submit button on the site is having some problems...

-DNG
 

Hey.. twice the post, twice the help.... [thumbsup2]



A smile is worth a thousand kind words. So smile, it's easy! :)
 
Thanks damber - right, without trying it I wouldn't have realised that - thanks for explaining.

and thanks for the links!
 
Hhmmm. maybe I wouldn't want to use the "for each..." method afterall. Seems the fields may not appear in the original order using this method.


unfortunately this is fundamental to my processing logic. I think I'll use a mixture of both.

both methods are great. I wish i'd known about it a while ago instead of coding around something I never needed to!
 

the fields wont necessarily appear in the expected order in any case.. you are reliant on the browser sending them in the order you wish, which is not gauranteed, especially in different browsers, however the link above is correct in that it is more CONSISTENT to use direct indexing to access the array.

A smile is worth a thousand kind words. So smile, it's easy! :)
 
Where would the fun be if it was..? [thumbsup]

A smile is worth a thousand kind words. So smile, it's easy! :)
 
If you require the form elements to always be in a certain order perhaps you could name them in such a way as to allow you to extrapolate the order.

So that your form elements look something like this:
<input type="text" name="box_1">
<input type="text" name="box_2">
<input type="text" name="box_3">
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top