2012-01-27 117 views
0

我有一个Java脚本代码将在一个形式JavaScript表单属性无效错误

function editCategory(categoryId) { 
$.ajax({ 
    type: "POST", 
    url: "/product/fetchEditCategory", 
    data: "categoryId=" + categoryId, 
    success: function(response){ 
     var productManagerForm = document.getElementById('productManager'); 
     productManagerForm.ceName.value = response.catName;........ 

我的JSP是设置一些值 -

<form id="productManager" name="productManager" action="/product/" method="post"> 
    <div id="editCategory"> 
     <tr> 
       <td style="font-weight:bold;">Category Name</td> 
       <td><input type="text" id="ceName" /></td>    
      </tr> 
</div>  
<td><a href="#editCategory" id="cat" onclick="editCategory('p1')">edit</a></td> 

我正在运行这段代码下面的错误 -

Message: 'ceName' is null or not an object 

有人可以告诉我这里有什么问题吗?

回答

2

ceName无法作为productManagerForm的属性进行访问。

试试这个:

var ceName = document.getElementById('ceName'); 
ceName.value = response.catName;........ 
+0

This Works ....感谢您的帮助 – Sachin 2012-01-27 18:16:35

0

你一定要试试这个:

var productManagerForm = document.getElementById('productManager'); 
var ceName = productManagerForm.getElementById('ceName'); 
ceName.value = response.catName; 
+0

或GZ说什么 – 2012-01-27 18:05:56

0

不知道你想什么用此功能acheive,但

var productManagerForm = document.getElementById('productManager'); 

返回节点元件。 ceName是这个元素的一个子元素。不是这个元素的属性。您可以通过使用直接获得元素:

var ceName = document.getElementById("ceName"); 

或下降的节点树,直到找到这个......考虑ceName是ID,它是更快得到它直接使用到的getElementById() 。

希望这会有所帮助!

相关问题