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 bkrike 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 form name in function?

Status
Not open for further replies.

Quasibobo

Programmer
Oct 11, 2001
168
NL
Hello,

Although the problem title may give you a "duh!!" reaction it isn't thát simple (for me)... I need a function in which I can handle different form names. I already know the function does the job it is supposed to do, but only when it a static form name. The function is as follows:

function UpdateDropDown(id)
{
var e = id;
data = GetOptions(e);

var j = 1;
// clear down the dropdown before adding new entries into it.
document.form.DivisieID.options.length = 0;
for (var i=0; i < data.length; i++)
{
if (data == 'RETURN')
{
return true;
}
document.form.DivisieID.options[j]=new Option(data, data);
j++;
}
return true;
}

This is the working form and my idea was somthing like this:

function UpdateDropDown(thisForm, id)
{
var e = id;
data = GetOptions(e);

var j = 1;
// clear down the dropdown before adding new entries into it.
document.thisForm.DivisieID.options.length = 0;
for (var i=0; i < data.length; i++)
{
if (data == 'RETURN')
{
return true;
}
document.thisForm.DivisieID.options[j]=new Option(data, data);
j++;
}
return true;
}

In this function 'thisForm' should be the variable form name e.g. form1, form2 etc... I call this function as follows:

onChange="Javascript:UpdateDropDown('form" & Counter & "', document.form"&Counter&".SpecialismeID.options[document.form"&Counter&".SpecialismeID.selectedIndex].value)";

Another idea I tried is this:

field = "document."+thisForm+".DivisieID";
field.options.length = 0;

But I don't seem bright enough.... Help!

Any suggestions?


Don't eat yellow snow!
 

Use:

Code:
document.forms['yourFormName'].DivisieID

Incidentally, I would never name a form "form" as it is a reserved word, I believe, and could cause problems in certain cases.

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top