html - Clear out an error message instead of appending with javascript -
in html form have warn user has enter level in inputbox, if clicks button again clear off error message , print out again. add more error messages add error message appends end of previous message.
function validateform () { var msg = "" , result = true; if (document.examentry.name.value === "") { msg = document.createtextnode("you must indicate level"); document.getelementbyid('name-msg').appendchild(msg); document.getelementbyid('name-msg').style.color="red"; } }
<form name="examentry" method="post"> <input type="text" id="name" name="name"> <span id="name-msg"></span> <input type="button" name="submit" value="submit" onclick="validateform();"> </form>
here's jsbin
function validateform () { var result = true; if (document.examentry.name.value === "") { document.getelementbyid('name-msg').innerhtml= "you must indicate level"; document.getelementbyid('name-msg').style.color="red"; } }
<form name="examentry" method="post"> <input type="text" id="name" name="name"> <span id="name-msg"></span> <input type="button" name="submit" value="submit" onclick="validateform();"> </form>
Comments
Post a Comment