Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing Text Color when button is clicked

    I am trying to Change the text color of my buttons when they are clicked can somone tell me where to insert and what line of code needs inserted. I am very new to this, i kinda just got thrown into it at work here and am trying to make it happen so any help is greatly appreciated.

    // subfileWidget.js

    document.getElementsByClassName = function(cl) {
    var retnode = [];
    var myclass = new RegExp('\\b'+cl+'\\b');
    var elem = this.getElementsByTagName('*');
    for (var i = 0; i < elem.length; i++) {
    var classes = elem[i].className;
    if (myclass.test(classes)) {
    retnode.push(elem[i]);
    }
    }
    return retnode;
    };


    document.body.oldOnload = document.body.onload;
    document.body.onload = function (){
    if(document.body.oldOnload){
    document.body.oldOnload();
    }
    initSubfileWidget();
    };

    // newFunction
    function initSubfileWidget() {
    var subfileTables = document.getElementsByClassName('HATSTABLE');
    //alert('found :' + subfileTables.length);
    for(var i = 0; i < subfileTables.length; i++){
    var radios = subfileTables[i].getElementsByTagName('input');
    //alert('radios: ' + radios.length);
    for (var j = 0; j < radios.length; j++){
    if(radios[j].type.toUpperCase() == "RADIO"){
    //alert('value' + radios[j].value);
    radios[j].oldOnClick = radios[j].onclick
    radios[j].onclick = new Function("if(this.oldOnClick)this.oldOnClick();highlightRow(this);");
    attachCellEvent(radios[j]);
    }
    }
    }
    }

    function attachCellEvent(element){
    var tr = element.parentNode;
    while(tr.tagName.toUpperCase() != "TR"){
    tr = tr.parentNode;
    }
    var cells = tr.getElementsByTagName('td');
    for(var cellIndex = 0; cellIndex < cells.length; cellIndex ++){
    var functionText = cells[cellIndex].onclick;
    var regexp = /HATSForm\.subfile\_radiobutton_\d+/;
    var radioName = regexp.exec(functionText);
    cells[cellIndex].oldOnclick = cells[cellIndex].onclick;
    cells[cellIndex].onclick = new Function("if(this.oldOnlclick)this.oldOnclick();"+ (radioName ? radioName + ".click();" : ""));
    }
    }

    function highlightRow(element){
    //alert('highlighting row');
    clearAllHighlighting(element);
    var tr = element.parentNode;
    while(tr.tagName.toUpperCase() != "TR"){
    tr = tr.parentNode;
    }
    tr.oldStyle = tr.className;
    tr.className = 'HATSTABLESELECTEDROW';
    }


    function clearAllHighlighting(element){
    var table = element.parentNode;
    while(table.tagName.toUpperCase() != "TABLE"){
    table = table.parentNode;
    }
    var rows = table.getElementsByTagName("TR");
    for (var k = 0; k < rows.length; k++){
    if(rows[k].oldStyle){
    rows[k].className = rows[k].oldStyle;
    }
    }
    }

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,373
    Thanks
    11
    Thanked 591 Times in 572 Posts
    <input value="click me" type="text" onclick="this.style.color='red' " />
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •