PDA

View Full Version : one function cancelling out the other (simple functions)



tk403
02-21-2009, 05:33 PM
I have a couple of functions within a function that each swap out different HTML code when their event handler is triggered. Here is the JS:

window.onload = prepBrackets;

function prepBrackets() {
var bracket = document.getElementById("bracket");
var taylork1_activator = document.getElementById("taylork1_name");
var taylork1_bracket = document.getElementById("taylork1_bracket");
var taylork2_activator = document.getElementById("taylork2_name");
var taylork2_bracket = document.getElementById("taylork2_bracket");

taylork1_activator.onclick = function() {
bracket.innerHTML = taylork1_bracket.innerHTML;
}
return false;

taylork2_activator.onclick = function() {
bracket.innerHTML = taylork2_bracket.innerHTML;
}
return false;
}

my problem is this: when I load the page, the first part of the function works fine -- when the taylork1_activator.onclick is triggered, the taylork1_bracket.innerHTML swaps with the bracket.innerHTML. But the second part does not work. The taylork2_activator.onclick event either isn't triggering or it's not executing the function correctly. When I comment out the first part and just leave the taylork2_activator.onclick function, it works fine. So there's something about the first part that is not allowing the second part to work. Ideas? Let me know if anyone wants the HTML. Thanks for any assistance.

vwphillips
02-21-2009, 05:59 PM
window.onload = prepBrackets;

function prepBrackets() {
var bracket = document.getElementById("bracket");
var taylork1_activator = document.getElementById("taylork1_name");
var taylork1_bracket = document.getElementById("taylork1_bracket");
var taylork2_activator = document.getElementById("taylork2_name");
var taylork2_bracket = document.getElementById("taylork2_bracket");

taylork1_activator.onclick = function() {
bracket.innerHTML = taylork1_bracket.innerHTML;
}

taylork2_activator.onclick = function() {
bracket.innerHTML = taylork2_bracket.innerHTML;
}
return false;
}

tk403
02-23-2009, 06:00 PM
Thanks!! Much appreciated.