In: Computer Science
Write a JavaScript function to get the values of form containing the following input fields:
CODE
<!DOCTYPE html>
<html>
<head>
<script>
function getValues() {
var result = "";
result += "First Name: " + document.forms["myForm"]["fname"].value
+ "<br>";
result += "Last Name: " + document.forms["myForm"]["lname"].value +
"<br>";
result += "Address: " + document.forms["myForm"]["address"].value +
"<br>";
result += "City: " + document.forms["myForm"]["city"].value +
"<br>";
result += "State: " + document.forms["myForm"]["state"].value +
"<br>";
document.getElementById("output").innerHTML = result;
}
</script>
</head>
<body>
<form name="myForm" onsubmit="return false">
First Name: <input type="text" name="fname"><br>
Last Name: <input type="text" name="lname"><br>
Address: <input type="text" name="address"><br>
City: <input type="text" name="city"><br>
State: <input type="text" name="state"><br>
<button type"button"
onclick="getValues()">Submit</button><br>
</form>
<hr>
<div>
<p id="output" />
</div>
</body>
</html>