gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot read property 'fname' of undefined at FillInfo()

转载 作者:太空宇宙 更新时间:2023-11-04 06:01:54 24 4
gpt4 key购买 nike

标题几乎说明了一切。

我正在制作一个表格,该表格将使用 div class = "well"在引号中返回您的名字和姓氏以及城市。我现在被困了几个小时,试图找出我做错了什么。

<script> /* get info from inputs and add it to a quote. */
function FillInfo(){
var fname = document.forms ["SIgnUpForm"] ["fname"].value;
var sname = document.forms ["SIgnUpForm"] ["sname"].value;
var city = document.forms ["SIgnUpForm"] ["city"].value;

document.getElementById("info").innerHTML = "Thank you" + " " + fname + " " + sname + "from" + " " + city + "." + " " + "You are now being considered as our next adventurer. Good luck!";
}
</script>

在正文中是:

<div class="heading2">
<div class="container2">
<p>Do you want to travel troughout space? Then fill out our form!</p><br>
<form name="SignUpForm" onsubmit="return validateForm()" method="get">
<input type="text" name="fname" placeholder="First name" required><br>
<input type="text" name="sname" placeholder="Last name" required><br>
<input type="text" name="city" placeholder="City" required><br><br>
<div id="info" class="well"></div>
<button class="otherpage" onclick="FillInfo();">Submit</button><br><br>
<a href="Mainpage.html" class="BeginLink">Return</a>
</form>
</div>
</div>

我希望它在我单击提交按钮时写下报价,但作为返回,我得到了这个:

Uncaught TypeError: Cannot read property 'fname' of undefined at FillInfo (things i put into inputs name, city) at HTMLButtonElement.onclick (things i put into inputs name, city)

最佳答案

我想你只是打错了表单名称

您的 Html 代码:SignUpForm

您的 Javascript 代码:SIgnUpForm

我修复了它,它对我有用。

关于javascript - 未捕获的类型错误 : Cannot read property 'fname' of undefined at FillInfo(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57215473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com