I am doing a project for school and I need a form with at least two text entries with JavaScript code to request, accept and manipulate the text of the form. so this is what I have come up with and I have spent more time on this than I would like to admit.
I cannot get it to define the variable fullname. Help would be appreciated from this rookie. If I knew any less about coding I wouldn't be coding at all.
<head>
<script>
function sayHi(){
var firstName = document.getElementById("firstName");
var lastName = document.getElementById("lastName");
var fullName = firstName + lastName;
var name = fullName.value;
var txtOutput = document.getElementById("txtOutput");
txtOutput.value = "Hi there, " + name + "!"
}
</script>
<style>
legend {
background-color: #000;
color: #fff;
padding: 3px 6px;}
.txtoutput {
font: 1rem 'Fira Sans', sans-serif;
}
input {
margin: .4rem;
}
</style>
<body>
<form action = "">
<fieldset>
<legend>Tell us your name</legend>
<label>First: </label>
<input type = "text" id = "firstName" />
<label>Last:</label>
<input type="text" id="lastName"/>
<input type = "button" value = "click me" onclick = "sayHi()"/>
<input type = "text" id = "txtOutput" />
</form>
</body>
</html>