Combining 2 variables into a statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CES

    #1

    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.(formN ame).(FieldName ).getAttribute( "maxlength" );

    var maxChar =
    document.(formN ame)(FieldName) .getAttribute(" maxlength");

    var maxChar =
    document.(formN ame.FieldName). getAttribute("m axlength");

    var maxChar = document.(formN ame + "." +
    FieldName).getA ttribute("maxle ngth");

    etc...



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



    Thanks


  • kaeli

    #2
    Re: Combining 2 variables into a statement

    In article <ApudndJK4obO5Q CiRVn-tg@speakeasy.ne t>, 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.


    -------------------------------------------------

    Comment

    • CES

      #3
      Re: Combining 2 variables into a statement

      kaeli,
      Thanks for the help...
      CES

      "kaeli" <infinite.possi bilities@NOSPAM att.net> wrote in message
      news:MPG.1a0739 f775abe08398990 f@nntp.lucent.c om...[color=blue]
      > In article <ApudndJK4obO5Q CiRVn-tg@speakeasy.ne t>, 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]


      Comment

      Working...