I wish to perform different actions based upon the image displayed, like this:
<script language=”JavaScript” type=”text/JavaScript”>
<!–
function EnterKey() {
var bnt1;
var btn2;
var btn3;
btn1=String(document.images[‘btnFrom’].src);
btn2=String(document.images[‘btnSubject’].src);
btn3=String(document.images[‘btnMessage’].src);
if ((document.images[‘btnFrom’].src) == ‘images/letter_buttons/btnFrom_on.gif’) {
(do something…) ;
} else if ((document.images[‘btnSubject’].src) == “images/letter_buttons/btnSubject_on.gif”) {
(do something else…) ;
} else if ((document.images[‘btnMessage’].src) == “images/letter_buttons/btnMessage_on.gif”) {
(default action…) ;
}
}
//–>
</script>
This gives me the error: “document.images[‘btnFrom’].src is null or not an Object”
I’ve also tried:
<script language=”JavaScript” type=”text/JavaScript”>
<!–
function EnterKey() {
if ((document.images[‘btnFrom’].src) == ‘images/letter_buttons/btnFrom_on.gif’) {
(do something…) ;
} else if ((document.images[‘btnSubject’].src) == “images/letter_buttons/btnSubject_on.gif”) {
(do something else…) ;
} else if ((document.images[‘btnMessage’].src) == “images/letter_buttons/btnMessage_on.gif”) {
(default action…) ;
}
}
//–>
</script>
This gives no error, but nothing happens.
I’m sure the comparison is failing because “document.images[‘btnFrom’].src” isn’t evaluated as a string and “‘images/letter_buttons/btnFrom_on.gif'” is a string.
How do I evaluate the object “document.images[‘btnFrom’].src” as a string to make the comparison?