tags:

views:

37

answers:

1

I would like to grey out (disable) the previous row(s), every time I add a new one. Right now I could only disable the first one. Many thanks in advance. Following is what I could do so far:

<head>
<SCRIPTTYPE="text/javascript">
varcount="1";
functionaddRow(in_tbl_name){
vartbody=document.getElementById(in_tbl_name).getElementsByTagName("TBODY")[0];
varrow=document.createElement("TR");
vartd1=document.createElement("TD")
varstrHtml1="<SELECTNAME=\"sel_1\"><optionvalue=\"a\">a<optionvalue=\"b\">b<optionvalue=\"c\">c<optionvalue=\"d\">d</SELECT>";
td1.innerHTML=strHtml1.replace(/!count!/g,count);
row.appendChild(td1);
count=parseInt(count)+1;
tbody.appendChild(row);
myform.sel1.disabled=true;
}
functiondelRow(){
varcurrent=window.event.srcElement;
while((current=current.parentElement)&&current.tagName!="TR");
current.parentElement.removeChild(current);
}
</SCRIPT>
</head>
<body>
<div>
<formaction="#"method="POST"name="myform">
<divstyle="">
<TABLEID="mytable"name="mytable"border="1"STYLE="border-width:1pxorangedashed;background-color:#F0E68C;table-row-width:2;">
<TR>
<TD>
<selectsize="1"name="sel1">
<optionvalue="a">a</option>
<optionvalue="b">b</option>
<optionvalue="c">c</option>
<optionvalue="d">d</option>
</select>
</TD>
</TR>
</TABLE>
</div>
<div>
<INPUTTYPE="Button"onClick="addRow('mytable')"VALUE="Add">
</div>
</form>
</div>
</body>
+1  A: 

Apply a CSS on that row. Row's don't have any concept of being "disabled" - they are simply rows. How they appear is driven by CSS.

Update: If you want to disable the form inputs in the row, simply find that element in the previous row, using e.g. jQuery, or manually (using DOM methods) if the DOM path of the SELECT is always the same.

Ondra Žižka
Thank you so much. How can I write the same script without having to type the select options within the JavaScript? Because my list of option is very long:<select size="1" name="sel1"> <option value="a">a</option> <option value="b">b</option> <option value="c">c</option> <option value="d">d</option> and many more....
DGT
If you wan't to use JS to generate the same select for each row, pls fill another question.
Ondra Žižka