Forum Moderators: open
Here is the VB code they provide, I need it in JS.
For Each Item in Upload.Form
If Item.name = "FORM_SELECT" Then
Response.Write Item.Value & "<BR>"
End If
Next
THANKS.
I'm assuming that we are client-side, and enumerating a form's elements.
A JS for..in loop is different to a VB for each, in that it enumerates an object's keys (as opp to values). A for..in will also spit out the 'length' key when enumerating a node list.
So enumeration via numerical index is better-suited.
var elements = Upload.form.elements;for(var k=0, elm; elm=elements[k]; k++)
{
if(elm.name == 'FORM_SELECT')
Response.Write(elm.value + '</BR>');
}
Yet, the inclusion of 'Response.Write' suggests that this is in fact server-side, and Upload.form is part of the environment (somehow). I'd need to know more - but it wouldn't be very different.
Upload.form doesn't have this. So what does it have?
I'll now assume that it is some form of enumerable.
It could be an object that is indexed
- by string keys
- by numerical keys
- both
It could be something darker, like a Dictionary.
Seeing as I don't know what structure is has, I'll try wrapping it in an enumerator, which will hopefully cover a number of possibilities.
var eUploadForm = new Enumerator(Upload.form);for(var elm; elm=eUploadForm.item(); eUploadForm.moveNext())
{
if(elm.name == 'FORM_SELECT')
Response.Write( elm.value + '<BR>');
}
// If you want to do it again later
// then rewind:
eUploadForm.moveFirst();
var eUploadForm = new Enumerator(Upload.Form);for(var elm; elm=eUploadForm.item(); eUploadForm.moveNext())
{
if(elm.name == 'FORM_SELECT')
Response.Write( elm.Value + '<BR>');
}
// If you want to do it again later
// then rewind:
eUploadForm.moveFirst();
It appears to be similar to enumeration of a
files collection when using JScript / WSH in your PC's file system, where you can take either approach - I add a custom getNext method to the Enumerator prototype that combines item and moveNext, so I can make the Enumerator approach meet my exacting aesthetic demands.
Out of interest, could you tell me whether or not the code I posted works too?
(I don't have ASP)
..but.. that's not fair!
The name condition changed from "FORM_SELECT" to "selClass"
Did you plug that in?
var fcnt = new Number(upload.Form.count);
a) the count property is a number already.
b) new Number() produces a Number object, which then must be evaluated to a number primitive. To convert a string to a number, it's better to leave out the
new, or just multiply by 1.