textarea value =在动态表单的页面上未定义

时间:2014-04-22 02:36:01

标签: javascript jquery mysql ajax

我不明白为什么我无法访问通过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按钮时,我调用alert来显示name字段的内容,我得到了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之一(也就是textarea存在正确的id),我仍然得到了UNDEFINED。

感谢任何帮助/

1 个答案:

答案 0 :(得分:0)

saveDish中的

.Value需要小写.value