Can someone help in adjusting this code ?

Discussion in 'JavaScript' started by Jean, Mar 29, 2006.

  1. #1
    I currently have the code listed below. This shows as a dark green reputation bar for two points and light green bar for 10 points. The problem is I want to add a third gold bar for reputation of 100 points. I tried to fiddle with it and ended up taking out all the reputation points. I reset it back but still left with my original problem. I tried to follow the codes for the green bars but I may have missed something.

    Thanks bunches to anyone that can help.


    <script type="text/javascript">
    <!--
    /* karma to images */

    var noKarma = "No Karma";

    var crossOver = 10; //Cross Over Point from small to large icons

    var bigInt = 10; //Number of Karma for Big Icon
    var smallInt = 2; //Number of Karma for Small Icon

    var positive = [
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_greenh.gif'], // Small Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_green.gif'], // Big Karma Icon
    ];


    var negative = [
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_neg.gif'], // Small Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_neg.gif'], // Big Karma Icon
    ];

    var noKarma="No Karma";

    var td=document.getElementsByTagName('td');
    for(i=0; i<td.length; i++) {
    if(td.item(i).width == '20%' && td.item(i).parentNode.innerHTML.match(/(Karma: (-)?(.+?))</i)) {
    var iTemp = RegExp.$1;
    var iHolder = 'Karma: ';
    if(RegExp.$3 == '0')
    iHolder += noKarma;
    else {
    var base = (RegExp.$2 == '-')? negative : positive;
    var kar = parseInt(RegExp.$3)
    var small = Math.round((kar % bigInt) / smallInt);
    var big = Math.round((kar - (kar % bigInt)) / bigInt);
    for(b=0; b<big; b++)
    {
    iHolder += '<img src="'+ base[0] +'" alt="'+ bigInt +' Karma" />';
    }
    for(s=0; s<small; s++)
    {
    iHolder += '<img src="'+ base[1] +'" alt="'+ smallInt +' Karma" />';
    }
    td.item(i).innerHTML = td.item(i).innerHTML.replace(iTemp,iHolder)
    }
    }
    }
    //-->
    </script>
     
    Jean, Mar 29, 2006 IP
  2. sacx13

    sacx13 Active Member

    Messages:
    438
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #2
    This is what you want ?
    Replace the images with other colors ...

    <script type="text/javascript">
    <!--
    
    
    var noKarma = "No Karma";
    
    var crossOver = 10; //Cross Over Point from small to large icons
    var bbbInt = 100; 
    var bigInt = 10; //Number of Karma for Big Icon
    var smallInt = 2; //Number of Karma for Small Icon
    
    var positive = [
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_greenh.gif'], // Small Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_green.gif'], // Big Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_neg.gif'], // Big Karma Icon
    ];
    
    
    var negative = [
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_neg.gif'], // Small Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_neg.gif'], // Big Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_greenh.gif'], // Small Karma Icon
    ];
    
    var noKarma="No Karma";
    
    var td=document.getElementsByTagName('td');
    for(i=0; i<td.length; i++) {
    if(td.item(i).width == '20%' && td.item(i).parentNode.innerHTML.match(/(Karma: (-)?(.+?))</i)) {
    var iTemp = RegExp.$1;
    var iHolder = 'Karma: ';
    if(RegExp.$3 == '0')
    iHolder += noKarma;
    else {
    var base = (RegExp.$2 == '-')? negative : positive;
    var kar = parseInt(RegExp.$3)
    var small = Math.round((kar % bbbInt) / smallInt);
    var big = Math.round((kar - (kar % bbbInt)) / bigInt);
    var bbb = Math.round((kar - (kar % bbbInt)) / bbbInt);
    
    if (kar>100)
    {
    
    for(bb=0; bb<bbb; bb++)
    {
    iHolder += '<img src="'+ base[2] +'" alt="'+ bbbInt +' Karma" />';
    }
    
    }
    else 
    {
    for(b=0; b<big; b++)
    {
    iHolder += '<img src="'+ base[0] +'" alt="'+ bigInt +' Karma" />';
    }
    
    for(s=0; s<small; s++)
    {
    iHolder += '<img src="'+ base[1] +'" alt="'+ smallInt +' Karma" />';
    }
    }
    
    td.item(i).innerHTML = td.item(i).innerHTML.replace(iTemp,iHolder)
    }
    }
    }
    //-->
    </script>
    
    Code (markup):
     
    sacx13, Mar 30, 2006 IP
  3. Jean

    Jean Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Interesting result.

    I get 1 gold for a member that has 130 points and nothing else. That person should have 1 gold and 3 light green.

    I also get 5 dark green for a member that has 10 points and they should have 1 light green.

    And 18 dark green for a member that has 18 points. So the light green seems to have disappeared ?
     
    Jean, Mar 30, 2006 IP
  4. sacx13

    sacx13 Active Member

    Messages:
    438
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #4
    So if you have 143 Karma you need to have 1Gold 4GreenLight and 3GreenDark ?

    Regards
    Adrian
     
    sacx13, Mar 31, 2006 IP
  5. Jean

    Jean Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes that is what should come out except the dark green are worth 2 points so you will actually only have 2 dark greens.

    I gather this is not an easy a code to fix as I thought. LOL
     
    Jean, Mar 31, 2006 IP
  6. sacx13

    sacx13 Active Member

    Messages:
    438
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Tell me if is ok ...

    <script type="text/javascript">
    <!--
    
    
    var noKarma = "No Karma";
    
    var crossOver = 10; //Cross Over Point from small to large icons
    var bbbInt = 100; 
    var bigInt = 10; //Number of Karma for Big Icon
    var smallInt = 2; //Number of Karma for Small Icon
    
    var positive = [
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_greenh.gif'], // Small Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_green.gif'], // Big Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_neg.gif'], // Big Karma Icon
    ];
    
    
    var negative = [
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_neg.gif'], // Small Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_neg.gif'], // Big Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_greenh.gif'], // Small Karma Icon
    ];
    
    var noKarma="No Karma";
    
    var td=document.getElementsByTagName('td');
    for(i=0; i<td.length; i++) {
    if(td.item(i).width == '20%' && td.item(i).parentNode.innerHTML.match(/(Karma: (-)?(.+?))</i)) {
    var iTemp = RegExp.$1;
    var iHolder = 'Karma: ';
    if(RegExp.$3 == '0')
    iHolder += noKarma;
    else {
    var base = (RegExp.$2 == '-')? negative : positive;
    var kar = parseInt(RegExp.$3)
    
    var small = Math.round(((kar % bbbInt)%bigInt) / smallInt);
    var big = Math.round(((kar-small) % bbbInt) / bigInt);
    var bbb = Math.round((kar - (kar % bbbInt)) / bbbInt);
    
    
    for(bb=0; bb<bbb; bb++)
    {
    iHolder += '<img src="'+ base[2] +'" alt="'+ bbbInt +' Karma" />';
    }
    
    for(b=0; b<big; b++)
    {
    iHolder += '<img src="'+ base[0] +'" alt="'+ bigInt +' Karma" />';
    }
    
    for(s=0; s<small; s++)
    {
    iHolder += '<img src="'+ base[1] +'" alt="'+ smallInt +' Karma" />';
    }
    
    
    td.item(i).innerHTML = td.item(i).innerHTML.replace(iTemp,iHolder)
    }
    }
    }
    //-->
    Code (markup):
     
    sacx13, Mar 31, 2006 IP
  7. Jean

    Jean Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I changed the third URL from the red negative to the gold one andYAHHHHHHHHHHHHH it works. Copywrite it as proboards have been trying to get it to work and you did it. Thank you bunches so much.
     
    Jean, Mar 31, 2006 IP
  8. sacx13

    sacx13 Active Member

    Messages:
    438
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #8
    I'm glad to hear that.

    Regards
     
    sacx13, Apr 1, 2006 IP
  9. Jean

    Jean Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I am bringing it up again as I was hoping that another adjustment can be made.

    I have an active board were exalting is done in a positive way. I currently have this code to show a dark green icon for every 2 points/a light green for every 10 points and a gold for every 100 points. What I want to do is add something that will allow another icon ( silver) to represent 1,000 points. It was a hard code to enter in the beginning to get it just right so I will understand if you can't do it.

    This is the icon I will use for the silver rep points..http://i30.photobucket.com/albums/c323/EquineExperience/rep-silver.gif

    Anyways here is the code as it stands now...

    <script type="text/javascript">
    <!--


    var noKarma = "No Karma";

    var crossOver = 10; //Cross Over Point from small to large icons
    var bbbInt = 100;
    var bigInt = 10; //Number of Karma for Big Icon
    var smallInt = 2; //Number of Karma for Small Icon

    var positive = [
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_greenh.gif'], // Small Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_green.gif'], // Big Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_gold.gif'], // Big Karma Icon
    ];


    var negative = [
    ['http://i30.photobucket.com/albums/c323/EquineExperience/replightred.gif'], // Small Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_neg.gif'], // Big Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_greenh.gif'], // Small Karma Icon
    ];

    var noKarma="No Karma";

    var td=document.getElementsByTagName('td');
    for(i=0; i<td.length; i++) {
    if(td.item(i).width == '20%' && td.item(i).parentNode.innerHTML.match(/(Karma: (-)?(.+?))</i)) {
    var iTemp = RegExp.$1;
    var iHolder = 'Karma: ';
    if(RegExp.$3 == '0')
    iHolder += noKarma;
    else {
    var base = (RegExp.$2 == '-')? negative : positive;
    var kar = parseInt(RegExp.$3)

    var small = Math.round(((kar % bbbInt)%bigInt) / smallInt);
    var big = Math.round(((kar-small) % bbbInt) / bigInt);
    var bbb = Math.round((kar - (kar % bbbInt)) / bbbInt);


    for(bb=0; bb<bbb; bb++)
    {
    iHolder += '<img src="'+ base[2] +'" alt="'+ bbbInt +' Karma" />';
    }

    for(b=0; b<big; b++)
    {
    iHolder += '<img src="'+ base[0] +'" alt="'+ bigInt +' Karma" />';
    }

    for(s=0; s<small; s++)
    {
    iHolder += '<img src="'+ base[1] +'" alt="'+ smallInt +' Karma" />';
    }


    td.item(i).innerHTML = td.item(i).innerHTML.replace(iTemp,iHolder)
    }
    }
    }
    //-->
    </script>
     
    Jean, Nov 1, 2006 IP
  10. Jean

    Jean Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Can ANYONE help please.
     
    Jean, Nov 4, 2006 IP
  11. Jean

    Jean Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I really would appreciate any help.
     
    Jean, Nov 9, 2006 IP
  12. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #12
    Here is the solution
    var bbbbInt = 1000;


    var positive = [
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_greenh.gif'], // Small Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_green.gif'], // Big Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_gold.gif'], // Big Karma Icon
    ],
    ['http://i30.photobucket.com/albums/c323/EquineExperience/rep-silver.gif'] // BBig Karma Icon
    ]
    ;

    var bbbb = Math.round((kar - (kar % bbbbInt)) / bbbbInt);


    for(bb=0; bb<bbbb; bb++)
    {
    iHolder += '<img src="'+ base[3] +'" alt="'+ bbbbInt +' Karma" />';
    }
     
    it career, Nov 10, 2006 IP
  13. Jean

    Jean Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Thanks itcareer but before I put it on my site can you verify that I have it right.:p

    <script type="text/javascript">
    <!--


    var noKarma = "No Karma";

    var crossOver = 10; //Cross Over Point from small to large icons
    var bbbbInt = 1000;
    var bbbInt = 100;
    var bigInt = 10; //Number of Karma for Big Icon
    var smallInt = 2; //Number of Karma for Small Icon

    var positive = [
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_greenh.gif'], // Small Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_green.gif'], // Big Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_gold.gif'], // Big Karma Icon
    ];
    ['http://i30.photobucket.com/albums/c323/EquineExperience/rep-silver.gif'] // BBig Karma Icon
    ]
    ;

    var negative = [
    ['http://i30.photobucket.com/albums/c323/EquineExperience/replightred.gif'], // Small Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_neg.gif'], // Big Karma Icon
    ['http://i30.photobucket.com/albums/c323/EquineExperience/reputation_greenh.gif'], // Small Karma Icon
    ];

    var noKarma="No Karma";

    var td=document.getElementsByTagName('td');
    for(i=0; i<td.length; i++) {
    if(td.item(i).width == '20%' && td.item(i).parentNode.innerHTML.match(/(Karma: (-)?(.+?))</i)) {
    var iTemp = RegExp.$1;
    var iHolder = 'Karma: ';
    if(RegExp.$3 == '0')
    iHolder += noKarma;
    else {
    var base = (RegExp.$2 == '-')? negative : positive;
    var kar = parseInt(RegExp.$3)

    var small = Math.round(((kar % bbbInt)%bigInt) / smallInt);
    var big = Math.round(((kar-small) % bbbInt) / bigInt);
    var bbb = Math.round((kar - (kar % bbbInt)) / bbbInt);
    var bbbb = Math.round((kar - (kar % bbbbInt)) / bbbbInt);

    for(bb=0; bb<bbbb; bb++)
    {
    iHolder += '<img src="'+ base[3] +'" alt="'+ bbbbInt +' Karma" />';
    }

    for(b=0; b<big; b++)
    {
    iHolder += '<img src="'+ base[0] +'" alt="'+ bigInt +' Karma" />';
    }

    for(s=0; s<small; s++)
    {
    iHolder += '<img src="'+ base[1] +'" alt="'+ smallInt +' Karma" />';
    }


    td.item(i).innerHTML = td.item(i).innerHTML.replace(iTemp,iHolder)
    }
    }
    }
    //-->
    </script>
     
    Jean, Nov 10, 2006 IP
  14. Jean

    Jean Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I tried it the way I have it above as no one answered to tell me it was wrong and all the icon boxes dissapeared so can someone tell me where the corrections actually go in the script, please.
     
    Jean, Nov 12, 2006 IP
  15. Jean

    Jean Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Can someone tell me where the additions go---please.
     
    Jean, Nov 16, 2006 IP
  16. PayItForward

    PayItForward Peon

    Messages:
    752
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Tell me if this works:

     
    PayItForward, Nov 16, 2006 IP
  17. Jean

    Jean Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    PIF--I tried it and only the light green ( worth 10 points) and the dark green ( worth 2 points) showed up.

    Those members that had gold reputation bars did not show anything other than the green ones.:confused:
     
    Jean, Nov 17, 2006 IP
  18. Jean

    Jean Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Can anyone help.:)
     
    Jean, Nov 21, 2006 IP