function myFunc() {
console.log("entered");
document.write('Submitted Data');
var firstname = document.getElementById("fname").value;
var lastname = document.getElementById("lname").value;
document.writeln("Your full name is:" + firstname + lastname);
}
<form>
<label> Firstname </label>
<input type="text" name="firstname" id="fname" size="15" /> <br> <br>
<label> Lastname</label>
<input type="text" name="lastname" id="lname" size="15" /> <br> <br>
<label>
Gender :
</label><br>
<input type="radio" name="male" /> Male <br>
<input type="radio" name="female" /> Female
<br>
<br>
<input type="button" value="Submit" onclick="myFunc()" />
</form>
单击提交后,它不会获取名字并在控制台中显示错误值 null。有人可以帮忙吗?整个代码保存在一个 HTML 页面中
月关宝盒
相关分类