Connecting Tech Pros Worldwide Help | Site Map

Combining 2 variables into a statement

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 11:23 AM
CES
Guest
 
Posts: n/a
Default Combining 2 variables into a statement

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, 11:24 AM
kaeli
Guest
 
Posts: n/a
Default 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, 11:25 AM
CES
Guest
 
Posts: n/a
Default 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]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.