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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to concatenate as non-string ? 1

Status
Not open for further replies.

anlogyxz

Technical User
Feb 13, 2008
3
US
Hi,

I am having trouble figuring out how to concatenate the following (but not as a string):

A page is dynamically generated via ASP. There are multiple input fields similar to below:
<input type="text" name="Input1Field">
<input type="text" name="Input2Field">
<input type="text" name="Input3Field">

And so on....

I am using a global javascript function to check that data has been entered in each field. However, because these are dynamically generated form input fields, I cannot know in advance how many there will be (Input[n]Fields above are also dynamically labeled).

So, in my Javascript function, I need to have

for(x=0;x<max;x++)
{
var check = form.Input[x]Item.value
}

for each x... so I can capture values for each input field.



When I try to concatenate the above as

for(x=0;x<3;x++)
{
var check = "form.Input" + x +"Item.value"
//I have an alert function to check if value is captured
alert(check)
}

I get an alert that reads
"form.Input1Item.value" or
"form.Input2Item.value" or
"form.Input3Item.value"

which of course doesn't help me because I need the value of the input field and not the string...

I hope this makes sense... I can't use an array because I don't know how many items I will have per form section...


So, in short, I need to be able to concatenate
form.Input[x]Item.value for each x but retain this as non-string


Any input would be appreciated.

Thanks!
 
there are a few ways to do this. try replacing your for-loop with this:

Code:
for(x=0;x<3;x++)
{
   var check = document.forms['YourFormName'].elements['Input' + x + 'Item'].value;
   alert(check);
}

----
star.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top