I am finding it hard to use js in html as i am new to this. I have tried changing around many different things to get it to work but nothing has been successful. Any advice would be greatly appreciated.
I have tried everything from changing the input types, actions, if and else if statements, alert function and many more.
function validation() {
var name = document.getElementById('Name').value;
var email = document.getElementById('Email').value;
var tel = document.getElementById('Telephone').value;
if (Name == '' || Email == '' || Telephone == '')
alert('action required')
return false;
} else if (name.length < 4) {
alert("action required")
return false;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="utf-8">
<link rel="stylesheet" href="css/WebForm.css">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>COM111 | WebForm | B0076234</title>
<meta name="viewport" content="width = device-width, inital-scale = 1.0">
<script src="assignment2/ass2script.js"></script>
<h1 id="h1">Welcome To My WebForm</h1>
<h2 id="h2"> CV Request</h2>
</head>
<body>
<!-- form -->
<form action="" method="post" onsubmit="return validation()">
<div class="wrap">
<div class="form1">
<div class="input-fields">
<input type="text" class="input" placeholder="Name" id="name">
<input type="email" class="input" placeholder="Email" id="Email">
<input type="tel" class="input" placeholder="Telephone" id="Telephone">
<input type="text" class="input" placeholder="Company" id="Telephone"><br>
<input type="submit" name="submit" value="Insert now">
<!--buttons-->
<label>Short CV
<input type="radio" checked="checked">
</label> <br>
<label>Long CV
<input type="radio">
</label>
<!-- messgebox -->
</div>
<div class="message">
<textarea placeholder="Message"></textarea>
<div class="btn">send</div>
</div>
</div>
</div>
</form>
<!--buttons-->
<div id="eresult"></div>
<!-- javascript -->
<script type="text/javascript">
</script>
</body>
</html>
`.
– Apr 09 '19 at 21:10