gpt4 book ai didi

javascript - 动态表单页面上的文本区域值 = 未定义

转载 作者:行者123 更新时间:2023-11-30 00:21:22 25 4
gpt4 key购买 nike

我不明白为什么我无法访问通过 AJAX/MySQL 动态生成的表单上的字段值。

表单模板如下所示:

<form class="dishform" id='" + d.dish_id + "FF' action="#" method="post">
<fieldset>
<label for="dish_name">Name</label>
<textarea onblur="changedField(this);" id='" + d.dish_id + "n' name="dish_name" class="textarea-comment dish_name valid" maxlength="80">
default text from MySQL
</textarea>
<label for="dish_decription">Description</label>
<textarea onblur="changedField(this);" id='" + d.dish_id + "d' name="dish_description" class="textarea-comment dish_description valid" maxlength="240">more default text from MySQL here</textarea>
<img src="/wp-content/uploads/menu-icons/save-dish.png" alt="Save current dish changes" class="action-menu-buttons save-curr-dish" onclick="saveDish(\'' + d.dish_id + '\')">
</fieldset>
</form>

d.dish_id 值是唯一的表键,它看起来类似于“DSH0000000001”。

当我点击 saveDish 按钮时,我会调用警报来显示名称字段的内容,并且该值得到 UNDEFINED,但默认值的正确数字是:

function saveDish(thisId) {

var NameId = thisId + 'n' <--- all ids for "name" are created as "d.dish_id + n"

alert("NameID= " + NameId); <--- this shows "DSH0000000001n" so correct
alert("DINAM= " + document.getElementById(NameId).defaultValue); <--- this shows the defaultValue correctly to what is in the textarea from load
alert("VAL= " + document.getElementById(NameId).Value); <--- this one shows UNDEFINED
alert("HARD CODED ID VAL= " + document.getElementById('DSH0000000001n').Value); <--- this one shows UNDEFINED

};

即使我将 ID 硬编码为我可以在检查中看到的 ID 之一(即文本区域存在具有正确的 ID),我仍然得到 UNDEFINED。

感谢任何帮助/

最佳答案

saveDish中,.Value需要小写.value

关于javascript - 动态表单页面上的文本区域值 = 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23209398/

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