textarea值=在具有动态表单的页面上未定义

textarea value = undefined on page with dynamic forms

本文关键字:未定义 表单 动态 textarea      更新时间:2023-09-26

我不明白为什么我不能访问通过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,但defaultValue的右图:

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硬编码为我在inspect中看到的ID之一(即文本区域存在正确的ID),我仍然会得到UNDEFINED。

感谢任何帮助/

saveDish中,.Value需要降低.value