Forum Moderators: open

Message Too Old, No Replies

onclick changing class

         

electricocean

10:46 pm on Apr 1, 2007 (gmt 0)

10+ Year Member



Hello, I have a message system where the names of all of the subjects are on the left and you click it tothe the message body. I have onclick parameter in the <tr> which changes the class to make it a color of grey to know you selected the right one. When you selct a second message the first one stays selected and they don't go back to the originaol class which makes them black.

Javascript:

select:

function mailMessageSelect(ID,tdID,max){
curID = "message";

for(var i = 0; i < max; i++){
$(i-1).className = "mailNotSelected";
//alert($("mailList" + i-1).innerHTML);
}

document.getElementById(tdID).className = "mailSelected";

var url = "ajax/app_mailMessage.php";
var pars = "mail_mailID=" + ID;
var myAjax = new Ajax.Request(
url,
{
method: 'get',
parameters: pars,
onComplete: showResponse
});
}

deselect:

function disMessageSelect(ID,tdID,max){
curID = "message";

for(var i = 0; i < max; i++){
$(i-1).className = "mailNotSelected";
//alert(i-1);
}

document.getElementById(tdID).className = "mailSelected";

var url = "ajax/app_disMessage.php";
var pars = "dis_disID=" + ID;
var myAjax = new Ajax.Request(
url,
{
method: 'get',
parameters: pars,
onComplete: showResponse
});
}

thanks,
elictricocean

Dabrowski

11:01 pm on Apr 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just because you've assigned an onClick event doesn't mean there's automatically an onUnClick!

What you'll have to do is add code into your click function to *FIRST* set all rows back to default colour, then highlight the one you want.

Dabrowski

11:08 pm on Apr 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ignore that, I must be on drugs.

ok, that's not the way I'd do it, here's my take:


function TRclick( evt) {
var e = evt ¦¦ event;
var obj = e.target ¦¦ e.srcElement;

for( var e = 0; e < obj.parentNode.childNodes.length; e++)
if( obj.parentNode.childNodes[ e].tagName == "TR")
obj.parentNode.childNodes[ e].className = "not_selected";

obj.className = "selected";
}

Code written while tired, probably a syntax error somewhere but by the looks you know enough JS to understand it.