Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-10-2007, 04:28 PM   PM User | #1
dave700800
New to the CF scene

 
Join Date: Dec 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
dave700800 is an unknown quantity at this point
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;
}
}
}
dave700800 is offline   Reply With Quote
Old 12-10-2007, 05:27 PM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,456
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
<input value="click me" type="text" onclick="this.style.color='red' " />
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:20 PM.


Advertisement
Log in to turn off these ads.