【问题标题】:Enable form element in dynamic element list在动态元素列表中启用表单元素
【发布时间】:2012-03-29 07:26:25
【问题描述】:

我有一个动态生成的学生列表。我希望用户记录出勤率,如果缺席,无论是否被原谅。如果存在,则没有理由记录后者,我希望禁用该选项。

我的问题是列表是动态生成的,以包含用于考勤的表单元素(通过 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;
}

这似乎是动态表单内容中的常规问题,但我一直未能找到解决方案。

【问题讨论】:

    标签: javascript forms google-app-engine django-templates


    【解决方案1】:

    您可以使用elements-collection:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多