2012-03-12 93 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