Click to See Complete Forum and Search --> : Creating a variable to reference form fields


tiffy
05-07-2003, 05:52 PM
I am trying to do what I thought would be very simple.
I am trying to create a variable that I will increment to reference a field on a form but I keep getting the following error:"Value is null or not an object". Here is a code sample:

function timeValidation()
{
recNum = document.control.rCount.value;
i = recNum;
for (x = 1; x <= i; x++)
{
t = "stTime_";
t = t + x;
alert(t);//t = stTime_1

time = document.control.t;

var h = time.value.indexOf(":", 0);
.......so on and so forth.

*The form's name is 'control'. I have up to 54 form fields named 'stTime_1', 'stTime_2' and so on. I am just trying to loop through them by concatenating x to 'stTime_' but when I do a document.control.t the value is null. When I do a document.control.stTime_1 I get the form value. I have done alerts and I know that t the first time through the loop t = 'stTime_1'. Any ideas on how I can make document.control.t reference stTime_1 correctly would be greatly appreciated.
Thanks to anyone that can help!!!!!

khalidali63
05-07-2003, 06:02 PM
you are a bit off
it should be something like this

function timeValidation()
{
var frm =document.control;

for (var x = 0; x < i; x++){
if(frm[x].type=="text"){
var field = eval('document.control.'+'stTime_'+x);
alert("field Name = "+field.name+", value = "field.value)
}
}

tiffy
05-08-2003, 09:39 AM
Khalid-
Thanks for your help!!!!!!