By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,259 Members | 1,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,259 IT Pros & Developers. It's quick & easy.

Combining 2 variables into a statement

P: n/a
CES
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
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In article <Ap********************@speakeasy.net>, No**@noSpam.com
enlightened us with...
All,
This Line works:

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


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
-------------------------------------------------
Jul 20 '05 #2

P: n/a
CES
kaeli,
Thanks for the help...
CES

"kaeli" <in********************@NOSPAMatt.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <Ap********************@speakeasy.net>, No**@noSpam.com
enlightened us with...
All,
This Line works:

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


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
-------------------------------------------------

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.