I have a strange problem in a very simple form validation script. Using Chrome and Firefox there is no problem, but using safari the innerHTML of my <p>
doesn't change correctly. The second problem is that I can't show it in a snippet because Snippets are too small. If a user first types an @ then a number and removes the number again, i got a mixed error message. (error message 3 and the second line of message 6). If I simply rescale the safari window by hand, the second line disappears. The same happens with the combination of a / and a number or a . and a number. Like you can see in the code.
Preview of the website: Preview
To produce the error/bug i did this problem in third img in the green box:
Fill in an @
Add a number
Remove the Number
This is my HTML:
<h3 id="forms">Forms</h3>
<div class="forms">
<form>
<div class="input"><input placeholder="name" name="name" type="text" oninput="checkname(this.id)" id="name"><div><p id="namereaction" class="reaction"></p></div></div>
<div class="input"><input placeholder="firstname" name="name" type="text" oninput="checkname(this.id)" id="firstname"><div><p id="firstnamereaction" class="reaction"></p></div></div>
<div class="input"><input placeholder="mail" name="mail" type="email" oninput="checkmail()" id="mail"><div><p id="mailreaction" class="reaction"></p></div></div>
<div class="input"><textarea name="text" id="textarea"></textarea><div id="textreactionbox"><p id="textareareaction" class="reaction"></p></div></div>
<div class="input"><input type="submit" name="submit" value="submit"></div>
</form>
</div>
And my JS:
function checkname(id){
var error="";
var value = document.getElementById(id).value;
if(value.length<1){
error = "Please fill in your (first)name.";
}
if(value.length>50){
error = "Please fill in your (first)name. Your name is to long.";
}
if (value.indexOf("@") > -1 ) {
error = "I think you are filling in your emailadress";
}
if (value.indexOf(".") > -1 ) {
error = "Please check your (first)name, most names don't have a '.'.";
}
if (value.indexOf("/") > -1 ) {
error = "Please check your (first)name, most names don't have a '/'.";
}
var matches = value.match(/\d+/g);
if (matches != null) {
error = "Please check your (first)name, we are all people, our (first)name doesn't contain a number.";
}
if(error.length>1){
document.getElementById(id+"reaction").innerHTML=error;
}else{
document.getElementById(id+"reaction").innerHTML="";
}
}