Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Javascript in Opera

I'm puzzled

4:05 pm on Dec 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

I have a bit of Javascript that checks to see whether two form fields match. If they don't, it switches the color of the labels to red, and if they do it puts them back to whatever they started out as. It works as intended in IE and Gecko-based browsers. In konqueror, it does nothing, and I can live with that. (I have server-side input checking. The javascript is just intended as a convenience for users who have it turned on.) Unfortunately, in Opera, the color change to red is successful, but the change back to the original color never happens. Anyone know why? The code is short, so I'll include it here.

var label1 = document.getElementById('cfEmail1');
var label2 = document.getElementById('cfEmail2');
var lc1 = label1.style.color;
var lc2 = label2.style.color;

function matchmail() {
if ((document.forms.cform.email1.value == document.forms.cform.email2.value) (document.forms.cform.email1.value == '' document.forms.cform.email2.value == ''))
label1.style.color = lc1;
label2.style.color = lc2;
label1.style.color = '#f00';
label2.style.color = '#f00';

matchmail() is called as the onchange event handler for each of the two form fields.