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!

append a number to a form variable inside function

Status
Not open for further replies.

mat41

Programmer
Mar 7, 2004
91
AU
Hello Javascript gurus. This part of a function is troubling me, am I on the rite track?

for (i = 1; i < theForm.ExtraHourPossibles.value; i++)
{
var fname = theForm.extraHours+i.value
alert(fname);
}

Specifically this line:
var fname = theForm.extraHours+i.value

My objective is for the fname value to generate:
theForm.extraHours1.value
theForm.extraHours2.value
theForm.extraHours3.value
theForm.extraHours4.value

Thankyou in advance
 
Code:
var fname = theForm["extraHours" + i].value                    
alert(fname);

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Webflo
 
Nice!!!! I would never have tried it without the period after the 'm' in 'form' (how does it know?)

you have a fine day :eek:)
 
May I trouble you for another help?

for (i = 1; i < theForm.ExtraHourPossibles.value; i++)
{
var fname = theForm["extraHours" + i].value
if (fname != "") && (isNaN(parseInt(fname)))
{
alert("Additional hours must be valid numbers only.");
}
}

Can I not do this?
if (fname != "") && (isNaN(parseInt(fname)))
my objective is to say if there is some syntax present it must be a number

Thank you in advance
 
Problem solved looks like I was missing a set of (). the following worked

if ((isNaN(parseInt(fname))) && (fname != ""))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top