Connecting Tech Pros Worldwide Forums | Help | Site Map

Combining 2 variables into a statement

CES
Guest
 
Posts: n/a
#1: Jul 20 '05
All,

I sorry for the 101 question but how do you combine 2 var into a document
statement i.e.



This Line works:



var maxChar = eval("document." + formName + "." + FieldName +
".getAttribute(\"maxlength\");");



But any variation without the eval() statment dosen't:



var maxChar =
document.(formName).(FieldName).getAttribute("maxl ength");

var maxChar =
document.(formName)(FieldName).getAttribute("maxle ngth");

var maxChar =
document.(formName.FieldName).getAttribute("maxlen gth");

var maxChar = document.(formName + "." +
FieldName).getAttribute("maxlength");

etc...



Can this be executed with out using eval()??



Thanks



kaeli
Guest
 
Posts: n/a
#2: Jul 20 '05

re: Combining 2 variables into a statement


In article <ApudndJK4obO5QCiRVn-tg@speakeasy.net>, None@noSpam.com
enlightened us with...[color=blue]
> All,
> This Line works:
>
>
>
> var maxChar = eval("document." + formName + "." + FieldName +
> ".getAttribute(\"maxlength\");");
>[/color]

maxChar = document.forms[formName].elements[FieldName];
would get the element.

adding on the .getAttribute("maxlength") should work, but I didn't test
it.

So...
maxChar = document.forms[formName].elements[FieldName].getAttribute
("maxlength");

Assuming there is an attribute called maxlength and defined variables
called formName and FieldName. I didn't look it up and attributes are
case-sensitive, so maxLength != maxlength and fieldName != FieldName.

-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
CES
Guest
 
Posts: n/a
#3: Jul 20 '05

re: Combining 2 variables into a statement


kaeli,
Thanks for the help...
CES

"kaeli" <infinite.possibilities@NOSPAMatt.net> wrote in message
news:MPG.1a0739f775abe08398990f@nntp.lucent.com...[color=blue]
> In article <ApudndJK4obO5QCiRVn-tg@speakeasy.net>, None@noSpam.com
> enlightened us with...[color=green]
> > All,
> > This Line works:
> >
> >
> >
> > var maxChar = eval("document." + formName + "." + FieldName[/color][/color]
+[color=blue][color=green]
> > ".getAttribute(\"maxlength\");");
> >[/color]
>
> maxChar = document.forms[formName].elements[FieldName];
> would get the element.
>
> adding on the .getAttribute("maxlength") should work, but I didn't test
> it.
>
> So...
> maxChar = document.forms[formName].elements[FieldName].getAttribute
> ("maxlength");
>
> Assuming there is an attribute called maxlength and defined variables
> called formName and FieldName. I didn't look it up and attributes are
> case-sensitive, so maxLength != maxlength and fieldName != FieldName.
>
> -------------------------------------------------
> ~kaeli~
> Jesus saves, Allah protects, and Cthulhu
> thinks you'd make a nice sandwich.
> http://www.ipwebdesign.net/wildAtHeart
> http://www.ipwebdesign.net/kaelisSpace
> -------------------------------------------------[/color]


Closed Thread