2012-03-12 90 views
0

我有一个动态生成的学生列表。我希望用户抓住考勤机,如果缺席,是否可以免除。如果存在,没有理由记录后者,我希望禁用该选项。在动态元素列表中启用表单元素

我的问题是,该列表是动态生成的,以包括参加考试的表单元素(通过django模板和谷歌应用程序引擎)。

即时通讯使用JavaScript来启用/禁用原谅/无效的单选按钮,但不能找出一个好办法。这似乎是一个正确的变量用法的简单问题,但我无法弄清楚(而且js不是我认识的超级好的语言)。

我试着去尝试在js函数如下:

//bring the name and ID of the clicked element in to the function 
function disable_enable(rdoIdIN, rdoNameIN){ 
//create a simple string of the common portion of the submitting button Im looking for, the word, "absent" 
var rdoId = rdoIdIN.substring(0,6); 
//use the dynamic portion of the clicked element name to generate the dynamic name of the element I want to enable 
var rdoStatusName = 'attendcategory' + rdoNameIN.substring(10) 

if (document.formname.rdoID == 'absent'){ 
    //enable the excused/unexcused elements 
    document.formname.rdoStatusName[0].disabled=false; 
    document.formname.rdoStatusName[1].disabled=false; 
} 

看起来这将是动态表单内容的常规问题,但我一直在寻找解决办法未果。

回答

0

您可以使用elements-collection

document.formname.elements[rdoStatusName][0].disabled=false; 
+0

谢谢,非常完美。 – techkilljoy 2012-03-13 22:01:07