hello folks! could anyone take a look at this code, and tell me why my function won’t display an error mesage inside the designated p-element? (actually it does, but it just flashes it, and it’s gone the next second) could someone please tell me what am I doing wrong, thanks…
<!DOCTYPE html>
<html lang="en">
<head>
<title>Survay Form</title>
<meta charset="utf-8">
<meta name="viewport" width="device-width, initial-scale=1.0">
<link rel="stilesheet" href="survay.css">
</head>
<body>
<h1 id="title">Survay Form</h1>
<p id="description">a form that survays...</p>
<form id="survey-form">
<label id="name-label">
<input id="name" type="text" placeholder="your name" required>
</label><br>
<label id="email-label">
<input id="email" type="email" placeholder="your email" required>
</label><br>
<label id="number-label">
<input id="number" type="text" placeholder="age (optional)">
</label>
</form><br>
<p id="eRr"></p>
<form>
<select id="dropdown">
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
<option>option 4</option>
</select>
</form><br>
<form>
<label for="aAA">
<input id="aAA" type="radio" value="aAA" name="aAa">aAA
</label>
<label for="AaA">
<input id="AaA" type="radio" value="AaA" name="aAa">AaA
</label>
<label for="AAa">
<input id="AAa" type="radio" value="AAa" name="aAa">AAa
</label>
<br>
<label for="bBB">
<input id="bBB" type="radio" value="bBB" name="bBb">bBB
</label>
<label for="BbB">
<input id="BbB" type="radio" value="BbB" name="bBb">BbB
</label>
<label for="BBb">
<input id="BBb" type="radio" value="BBb" name="bBb">BBb
</label>
</form>
<br>
<form>
<label for="xXX">
<input id="xXX" type="checkbox" value="xXX" name="xXx">xXX
</label>
<label for="XxX">
<input id="XxX" type="checkbox" value="XxX" name="xXx">XxX
</label>
<label for="XXx">
<input id="XXx" type="checkbox" value="XXx" name="xXx">XXx
</label>
<br>
<label for="zZZ">
<input id="zZZ" type="checkbox" value="zZZ" name="zZz">zZZ
</label>
<label for="ZzZ">
<input id="ZzZ" type="checkbox" value="ZzZ" name="zZz">ZzZ
</label>
<label for="ZZz">
<input id="ZZz" type="checkbox" value="ZZz" name="zZz">ZZz
</label>
</form><br>
<form>
<label class="myTextArea">post your comments and sugestions<br>
<textarea class="user-comments"></textarea>
</label>
<button onclick="checkTheValue()" type="submit">submit</button>
</form>
<script src="survay.js"></script>
</body>
</html>
function checkTheValue(){
var message,x;
x=(document.getElementById(“number”).value);
message =document.getElementById(“eRr”);
message.innerHTML="";
try {
if (isNaN(x)) throw “is not a number”;
if ((x).value == “”) throw “is empty”;
if ((x).value >9) throw “is too high”;
if ((x).value <1) throw “is too low”;
}
catch(err) {
message.innerHTML= "Input value " + err;
}
}
I do not have a clue, but some errors disappears when changing ” to "
https://jsfiddle.net/ejz87hao/
Press Tidy to show errors
thank you, I never noticed that…