Change color of font using javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abhubbart
    New Member
    • Sep 2007
    • 3

    Change color of font using javascript

    I want change the color on the font to red for the text within the div element.

    I have the following code.

    [HTML]
    <style type="text/css">
    .style2 {color: #000000}
    </style>
    [/HTML]
    [CODE=javascript]
    <script language="JavaS cript" type="text/JavaScript">
    function radio1(){
    document.form1. test12.style.co lor="#FF0000";}
    </script>[/CODE]
    [HTML]
    <form name="form1" method="post" action="submit. php">
    <p class="style2"> <input name="radType" type="radio" onClick="radio1 ()" value="new">Cha nge to red.</p>

    <div id="test12"><p class="style2"> You agree to the following by checking this box and clicking submit.</p></div>

    </form>[/HTML]


    I think that is the code, I cut out the extra stuff...My page works fine except changing that font color. please ignore any mistakes i might have made in copying.

    I hope this makes sense.
    Last edited by gits; Sep 19 '07, 07:51 AM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    instead of:

    [CODE=javascript]document.form1. test12
    [/CODE]
    use:

    [CODE=javascript]
    document.getEle mentById('test1 2')
    [/CODE]

    kind regards

    Comment

    • abhubbart
      New Member
      • Sep 2007
      • 3

      #3
      Originally posted by gits
      hi ...

      instead of:

      [CODE=javascript]document.form1. test12
      [/CODE]
      use:

      [CODE=javascript]
      document.getEle mentById('test1 2')
      [/CODE]

      kind regards

      I made the change you suggested. Although, I don't receive any errors. I don't get the desired results. I want the text in the html to change to red when the radio button is clicked.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        hi ...

        there has to be another error ... is the function called?

        try this ... that works:

        [HTML]
        <div id="test" style="color: green;">test</div>
        <input type="button" value="red it :)" onclick="docume nt.getElementBy Id('test').styl e.color = 'red';"/>
        [/HTML]
        kind regards

        Comment

        • abhubbart
          New Member
          • Sep 2007
          • 3

          #5
          Thank you so much for you help. The only thing i can figure out that was stopping it was the fact that i had the class defined in the <p> tag instead of the <div> tag. At any rate, i have it working now.

          Thanks again.

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            glad to hear you got it working ... post back to the forum anytime you have more quetsions ...

            kind regards

            Comment

            Working...