jkruer01
01-30-2003, 01:59 PM
I have the following code in a webpage:
<span id="linkA" style="color: green;" onClick="toggle( linkA )">-25% to 25%</span><br>
<span id="linkB" style="color: green;" onClick="toggle( linkB )">26% to 50%</span><br>
<span id="linkC" style="color: green;" onClick="toggle( linkC )">Greater than 50%</span><br>
and the following JavaScript function
function toggle( that )
{
switch( that.style.color )
{
case "green":
that.style.color = "red";
break;
case "red":
that.style.color = "green";
break;
}
switch( that )
{
case "linkA":
location.href="...";
alert( "linkA" );
break;
case "linkB":
location.href="...";
alert( "linkB" );
break;
case "linkC":
location.href="...";
alert( "linkC" );
break;
}
}
I want to be able to tell which ID was clicked. I thought that the "switch(that)" statement would work but it is not. How can I get the ID of that? Is it that.ID?
Thanks,
<span id="linkA" style="color: green;" onClick="toggle( linkA )">-25% to 25%</span><br>
<span id="linkB" style="color: green;" onClick="toggle( linkB )">26% to 50%</span><br>
<span id="linkC" style="color: green;" onClick="toggle( linkC )">Greater than 50%</span><br>
and the following JavaScript function
function toggle( that )
{
switch( that.style.color )
{
case "green":
that.style.color = "red";
break;
case "red":
that.style.color = "green";
break;
}
switch( that )
{
case "linkA":
location.href="...";
alert( "linkA" );
break;
case "linkB":
location.href="...";
alert( "linkB" );
break;
case "linkC":
location.href="...";
alert( "linkC" );
break;
}
}
I want to be able to tell which ID was clicked. I thought that the "switch(that)" statement would work but it is not. How can I get the ID of that? Is it that.ID?
Thanks,