Web Analytics Made Easy -
StatCounter putting string into an if statement - CodingForum

Announcement

Collapse
No announcement yet.

putting string into an if statement

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • putting string into an if statement

    How do i get the boxname as a string into the following code?

    boxname="pressme";
    if("document.form."+boxname+".checked" == true)
    { box="checked"; }

    If i hardcode the name,(document.form.pressme.checked), it works, but
    not as a string. Can anyone please help me with this?
    Regards / Stefan

  • #2
    Code:
    if (document.form.elements[boxname].checked) {
      ...
    }
    That's javascript square bracket notation. See my sig for more info on it.
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      Thanks

      Just tried it. Now it works like it should.
      Thanks a lot.
      /stefan

      Comment

      Working...
      X