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

How to use function with different form names, and perhaps diff fields

Status
Not open for further replies.

WestSide2003

Technical User
Jan 22, 2003
42
0
0
US
Hi,

I have this function that verifies credit card info....

I wanted to know....how can I use this same function on other pages in the site with different form names and perhaps different field names... right now I will settle for it working with the same field names but different form names.

Some of my pages have more than 1 form so I can't use document.forms[0].fieldName or whatever......

Currently I hardcoded the name of my form and its fields too

so I have statements like if(myformname.CreditCardNumber.value.length == 0) {
alert("Some Error");
}

However, I want to call this function from other pages and I get an error because its looking for the form "myformname", how can I make it more generic.. I am new to JavaScript, so if you respond, please keep that in mind.

Thanks

-WS
 
pass the form and textfield as parameters:
function Hello(TheForm,TheField)
{
alert(TheForm.name)
alert(TheField.value)
}

call it like this:
Hello(document.myformname,document.myformname.CreditCardNumber)

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top