Connecting Tech Pros Worldwide Help | Site Map

Combining 2 variables into a statement

  #1  
Old July 20th, 2005, 12:23 PM
CES
Guest
 
Posts: n/a
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


  #2  
Old July 20th, 2005, 12:24 PM
kaeli
Guest
 
Posts: n/a

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
-------------------------------------------------
  #3  
Old July 20th, 2005, 12:25 PM
CES
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I make this more efficient? (combining DataSet results with the results of a DB lookup.) Ken Fine answers 3 July 23rd, 2008 09:15 AM
A quick introduction to Java concepts 1 r035198x insights 3 April 5th, 2008 08:56 AM
combining serialized data Jon Slaughter answers 4 May 17th, 2007 02:15 PM
author index for Python Cookbook 2? Andrew Dalke answers 10 July 19th, 2005 12:26 AM