类型错误:对象不是一个函数,当它! [英] TypeError: object is not a function, when it is!

查看:94
本文介绍了类型错误:对象不是一个函数,当它!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法与一些Ajax功能。

我有一个需要更新记录​​的选项更改时,一个下拉列表。下面是JavaScript的一个片段:

 函数changeResponsibleParty(selectObj,targetDiv){
    VAR IDX = selectObj.selectedIndex;
    VAR其中= selectObj.options [IDX] .value的;
    目标=的document.getElementById(targetDiv);
    target.value =其中;
    document.forms [changeResponsibleParty]提交()。
}
 

和HTML:

 <表格名称=changeResponsibleParty行动=JavaScript的:changeResponsiblePartyAjax('project_todos');方法=邮报的风格=显示:内联;>

<输入类型=隐藏名称=todo_idID =todo_id_15值=15/>
<输入类型=隐藏名称=PROJECT_IDID =project_id_15值=2/>
<输入类型=隐藏名称=user_ID的ID =user_id_15值=/>

<选择名称=user_id_pickID =user_id_pick_15的onchange =changeResponsibleParty(这一点,user_id_15');风格=边界:0;>

<期权价值=0>任何< /选项>
<期权价值=1选择=选择>艾伦麦凯布< /选项>
<期权价值=2>托马斯·马丁内斯< /选项>
< /选择>
< /形式GT;
 

我现在用的功能,无论哪个选项我选择了(1是我user_ID的,这是我设置为当数据库记录值为1 <选择要更新一个隐藏的输入元素,因为出于某种原因,该标签被张贴1 / P>

有人能看到这里有什么问题?

解决方案

您使用 changeResponsibleParty 作为表单名称,也作为功能,这将导致冲突的名字。重命名它们中的一个。

I am having trouble with some Ajax functionality.

I have a single dropdown that needs to update a record when the option changes. Here is a snippet of the Javascript:

function changeResponsibleParty(selectObj, targetDiv){
    var idx = selectObj.selectedIndex;
    var which = selectObj.options[idx].value;
    target = document.getElementById(targetDiv);
    target.value = which;
    document.forms["changeResponsibleParty"].submit();
}

And the HTML:

<form name="changeResponsibleParty" action="javascript:changeResponsiblePartyAjax('project_todos');" method="post" style="display:inline;">

<input type="hidden" name="todo_id" id="todo_id_15" value="15" />
<input type="hidden" name="project_id" id="project_id_15" value="2" />
<input type="hidden" name="user_id" id="user_id_15" value="" />

<select name="user_id_pick" id="user_id_pick_15" onchange="changeResponsibleParty(this, 'user_id_15');" style="border:0;">

<option value="0">Anyone</option>
<option value="1" selected="selected">Allen McCabe</option>
<option value="2">Thomas Martinez</option>
</select>
</form>

I am using the function to update a hidden input element because for some reason, the tag was posting 1 regardless of which option I chose (1 is my user_id, which I set as selected if the database record value is 1.

Can anyone see what is wrong here?

解决方案

You use changeResponsibleParty as name for the form and also as name for the function, which will cause conflicts. Rename one of them.

这篇关于类型错误:对象不是一个函数,当它!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆