i have an input box whose value i want to clear if the user’s input is wrong. i want to accomplish this using the onblur event and a javascript function.
this is the textfield i want to apply the onblur function to:
<tr>
<td><input id="TryMe" type="text" onblur="checkMe('TryMe')"/></td>
</tr>
the function that does that is this:
<script>
function checkMe(elemID){
elem = document.getElementById(elemID);
if (elemID.value == "CORRECT"){
alert ("you are correct!");
}
else{
document.getElementById(numericElemID).value="";
document.getElementById(numericElemID).focus();
return false;
}
}
and it works as i intend it to. however, why is it that when i remove the “return false;” part, it does not work anymore:
else {
document.getElementById(numericElemID).value="";
document.getElementById(numericElemID).focus();
}
EDIT: including the javascript and the text input
1 Answer