1. This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
    For information on cookies and how you can disable them visit our Cookie Usage page.
    Dismiss Notice

JavaScript style color getElementsByTagName('SPAN') EXPERT NEEDED

Discussion in 'Web Development' started by boemboem, Aug 14, 2009.

  1. boemboem

    boemboem New Member

    I'm trying to lern javascript, but my knowledge doesn't cover what I want, so I could really use some help. I'm trying to make a lotto check form for our family.

    Can somebody explain me how to alter this code to color the font green even if the match isn't on the same place, please take a look at this image, it explains more then 1000 words.

    Here is an example, don't mind the banner, it's a family joke, so nothing commercial. :D it only works in IE at the moment.

    http://www.coldcharlie.nl/lotto.html

    Code:
    <SCRIPT TYPE="TEXT/JAVASCRIPT">
    // Check lotto
    
    function checkLotto() {
     var goed = frmTrekking.Getal
     var fout = frmGetallen.Opgegeven
     for (var z0=0;z0<goed.length;z0++){
      if (goed[z0]&&fout[z0]){
       if (goed[z0].value==fout[z0].value){
         fout[z0].parentNode.style.color='#00FF00';
         fout[z0].parentNode.getElementsByTagName('SPAN')[0].innerHTML+=goed[z0].value;
       }
       else {
         fout[z0].parentNode.style.color='#cc0000';
         fout[z0].parentNode.getElementsByTagName('SPAN')[0].innerHTML+=fout[z0].value;
    
       }
      }
     }
    
          }
    
    </script>
    Beneath is a graphical explaination, I really hopes this helps.


    [​IMG]


    I'l make you a free logo when it's working :D
     
  2. GDSweb.ca

    GDSweb.ca Moderator/Developer

    You could use the String Object Syntax....

    Code:
    stringObject.fontcolor(color)
    Such as:
    Code:
    var str="Change Me!";
    document.write(str.fontcolor("Red"));