I'm a beginner javascript user and I'm trying to get this html form to pass to this javascript function and output the name variable but all that happens when I click the button to submit is that the form input clears and it stays on the form not passing to the javascript.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Life Insurance Calculator</title>
<script type="text/javascript">
var title = "Welcome to Life Insurance Co..!";
//Declaring variable title
document.writeln(title.fontsize(8).fontcolor('red'));
//Printing out the title on the page
function Name(form){
var customername = document.getElementByID("name").value;
document.write(customername);
}
</script>
</head>
<body>
<form name = "LifeCalcForm" action="" method="get">
<p>To get a life insurance quote, please tell us about yourself.</p>
<p><i>Note:only those under the age of 80 and non-smokers may apply</i></p>
<p>Enter your name: <input type="text" name="name" /></p>
<input type="submit" value="Calculate" onClick="Name(this.form)">
</form>
</body>
</html>
document.writeafter the onload has fired. In you case that happens because theonclickalmost certainly fires after the onload. On top of that, you will need toreturn falsefrom youronclickto prevent the default submit behavior.type=buttonif you need just javascript but what you want to do here:document.write(customername)?