Changing HTML input text style color from javascript

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

    Changing HTML input text style color from javascript

    I am wondering why this does not work in javascript. The html color is
    set to automatic (none)

    element1, element2, etc are input fields (textboxes)

    document.myform .elements('elem ent-'+counter).styl e='color: #FF0000'

    Thanks
  • Evertjan.

    #2
    Re: Changing HTML input text style color from javascript

    Perdit wrote on 21 sep 2003 in comp.lang.javas cript:
    [color=blue]
    > I am wondering why this does not work in javascript. The html color is
    > set to automatic (none)
    >
    > element1, element2, etc are input fields (textboxes)
    >
    > document.myform .elements('elem ent-'+counter).styl e='color: #FF0000'[/color]

    document.myform (counter-1).style.color = '#FF0000'

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Tom

      #3
      Re: Changing HTML input text style color from javascript

      "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
      news:Xns93FE122 63EC3eejj99@194 .109.133.29...[color=blue]
      > Perdit wrote on 21 sep 2003 in comp.lang.javas cript:
      >[color=green]
      > > I am wondering why this does not work in javascript. The html color is
      > > set to automatic (none)
      > >
      > > element1, element2, etc are input fields (textboxes)
      > >
      > > document.myform .elements('elem ent-'+counter).styl e='color: #FF0000'[/color]
      >
      > document.myform (counter-1).style.color = '#FF0000'[/color]

      Let 's try another one:
      document.myform['element'+count er].style.color='# ff0000';

      Important things to note:
      - square brackets.
      - no dot or anything between "myform" and the opening bracket.
      - "myform" can be any string, as long as it is the same as
      the "name='myfo rm' " bit in the actual form opening tag.
      - counter can be an integer 1, or a string "1", but not "01" or " 1" with a
      space.

      If you want to use a hyphen (-) like in your example line of code, the
      element names should also be renamed to element-1, element-2, etc. I think
      hyphens are legal in element names, but am not sure.
      HTH
      Tom


      Comment

      • Richard Cornford

        #4
        Re: Changing HTML input text style color from javascript

        "Perdit" <cftranslate@ho tpop.com> wrote in message
        news:63d3768c.0 309211355.2fa73 135@posting.goo gle.com...[color=blue]
        >I am wondering why this does not work in javascript. The html
        >color is set to automatic (none)
        >
        > element1, element2, etc are input fields (textboxes)
        >
        > document.myform .elements('elem ent-'+counter).styl e='color: #FF0000'[/color]

        The elements collection of a form is an object so JavaScript property
        accessor syntax uses square brackets not parenthesises.

        <URL: http://jibbering.com/faq/#FAQ4_39 >

        The style property of an Element holds a reference to an object and
        assigning a CSS 'color' property to that object involves setting its
        color property:-

        document.forms['myform'].elements['element-'+

        counter].style.color = '#FF0000';

        Richard.


        Comment

        Working...