html - JavaScript switch not executing -
i have simple javascript code. switch not executed, reason, mystery me! stupid error have made?
function hndlev ( e ) { switch ( document.forms[0].zcode.length ) { case 1: document.forms[0].zcode.style.backgroundcolor = "ffcc33"; break; case 2: document.forms[0].zcode.style.backgroundcolor = "ffff33"; break; case 3: document.forms[0].zcode.style.backgroundcolor = "ccff33"; break; case 4: document.forms[0].zcode.style.backgroundcolor = "66ff33"; break; case 5: document.forms[0].zcode.style.backgroundcolor = "00ff33"; break; } } ... <body onload="setfocus();" onkeypress="hndlev(event);"> ... <input type="text" name="zcode" size="6" maxlength="6" class="code" />
function hndlev ( e ) { switch ( document.forms[0].zcode.value.length ) { case 1: document.forms[0].zcode.style.backgroundcolor = "ffcc33"; break; case 2: document.forms[0].zcode.style.backgroundcolor = "ffff33"; break; case 3: document.forms[0].zcode.style.backgroundcolor = "ccff33"; break; case 4: document.forms[0].zcode.style.backgroundcolor = "66ff33"; break; case 5: document.forms[0].zcode.style.backgroundcolor = "00ff33"; break; } }
try this
Comments
Post a Comment