convert variable to a value

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

    convert variable to a value

    i have a quick ? i have a variable that is named dynamically by
    combining values into a string, how would i then get the value of the
    string

    formname = "document.f orm" + count + ".quantity.valu e"


    I then need the value of the form element, not the value of the
    variable (formname).

    anyone?

  • Ivo

    #2
    Re: convert variable to a value

    "Cogswell" aks[color=blue]
    > i have a quick ?[/color]

    Do you also have a Shift-key?

    i have a variable that is named dynamically by[color=blue]
    > combining values into a string, how would i then get the value of the
    > string
    >
    > formname = "document.f orm" + count + ".quantity.valu e"
    >
    > I then need the value of the form element, not the value of the
    > variable (formname).
    >
    > anyone?[/color]

    No, please do consult this newsgroup's FAQ, especially:

    URL: http://www.jibbering.com/faq/#FAQ4_39



    Comment

    • RobG

      #3
      Re: convert variable to a value

      Cogswell wrote:[color=blue]
      > i have a quick ? i have a variable that is named dynamically by
      > combining values into a string, how would i then get the value of the
      > string
      >
      > formname = "document.f orm" + count + ".quantity.valu e"
      >
      >
      > I then need the value of the form element, not the value of the
      > variable (formname).[/color]

      formname = "document.f orm" + count + ".quantity.valu e"
      var theValue = eval(formname);

      However, given the general dislike of 'eval', I would propose the
      following:

      var formname = 'form' + count;
      var theValue = document.forms[formname].elements['quantity'].value;

      Have fun.

      --
      Rob

      Comment

      • Cogswell

        #4
        Re: convert variable to a value

        Thanks Rob for the non-smart ass response. Worked perfectly....

        Comment

        Working...