Hello , im a java programmer whos gotten tangled up in some
javascripts. Im really stuck on this one can , can aybody explain this
to me.
I have a javscript which is to clone a table row and insert it below
the current table row. this is the main part :
// New row function. Called by form button.
function newRow(baseRowI d, tableId) {
// Get a reference to the base row.
var baseRow = document.getEle mentById(baseRo wId)
// Clone the base row.
var newRow = baseRow.cloneNo de(true)
// Reset the value attribute of all INPUT & SELECT elements
// in the cloned row.
resetRow(newRow )
// Insert the cloned row after the last row in the table.
document.getEle mentById(tableI d).lastChild.ap pendChild(newRo w)
}
function resetRow(objRef ) {
for (var i = 0; i < objRef.childNod es.length; i++) {
// Reset ONLY input elements (NOT checkboxes or submit/reset
buttons)...
if (objRef.childNo des[i].nodeName.toUpp erCase() == "INPUT" &&
objRef.childNod es[i].getAttribute(" type").toUpperC ase() !=
"CHECKBOX" &&
objRef.childNod es[i].getAttribute(" type").toUpperC ase() !=
"SUBMIT" &&
objRef.childNod es[i].getAttribute(" type").toUpperC ase() !=
"RESET") {
objRef.childNod es[i].setAttribute(" value", "")
}
// ...and DISABLE submit buttons.
if (objRef.childNo des[i].nodeName.toUpp erCase() == "INPUT" &&
objRef.childNod es[i].getAttribute(" type").toUpperC ase() ==
"SUBMIT") {
objRef.childNod es[i].setAttribute(" disabled", "true")
}
// ...and rename input fileds.
if (objRef.childNo des[i].nodeName.toUpp erCase() == "INPUT" &&
objRef.childNod es[i].getAttribute(" name").toUpperC ase()=="CUSTOME R"){
objRef.childNod es[i].setAttribute(" disabled", "true")
objRef.childNod es[i].setAttribute(" value", "test")
//THIS DOES NOT WORK
objRef.childNod es[i].setAttribute(" name", "customer1" )
}
// ...and rename input fileds.
if (objRef.childNo des[i].nodeName.toUpp erCase() == "INPUT" &&
objRef.childNod es[i].getAttribute(" name").toUpperC ase() ==
"FR_DATE"){
objRef.childNod es[i].setAttribute(" disabled", "true")
objRef.childNod es[i].setAttribute(" value", "test")
//THIS DOES NOT WORK
objRef.childNod es[i].setAttribute(" name", "from_date1 ")
}
if (objRef.childNo des[i].childNodes.len gth > 0) {
resetRow(objRef .childNodes[i])
}
}
I works ok. In the new row i can set the value of input elements,
disable the input element but not change the name of the input
elements. Why is this ?
If anybody can see this i will be one happy++
Tim
javascripts. Im really stuck on this one can , can aybody explain this
to me.
I have a javscript which is to clone a table row and insert it below
the current table row. this is the main part :
// New row function. Called by form button.
function newRow(baseRowI d, tableId) {
// Get a reference to the base row.
var baseRow = document.getEle mentById(baseRo wId)
// Clone the base row.
var newRow = baseRow.cloneNo de(true)
// Reset the value attribute of all INPUT & SELECT elements
// in the cloned row.
resetRow(newRow )
// Insert the cloned row after the last row in the table.
document.getEle mentById(tableI d).lastChild.ap pendChild(newRo w)
}
function resetRow(objRef ) {
for (var i = 0; i < objRef.childNod es.length; i++) {
// Reset ONLY input elements (NOT checkboxes or submit/reset
buttons)...
if (objRef.childNo des[i].nodeName.toUpp erCase() == "INPUT" &&
objRef.childNod es[i].getAttribute(" type").toUpperC ase() !=
"CHECKBOX" &&
objRef.childNod es[i].getAttribute(" type").toUpperC ase() !=
"SUBMIT" &&
objRef.childNod es[i].getAttribute(" type").toUpperC ase() !=
"RESET") {
objRef.childNod es[i].setAttribute(" value", "")
}
// ...and DISABLE submit buttons.
if (objRef.childNo des[i].nodeName.toUpp erCase() == "INPUT" &&
objRef.childNod es[i].getAttribute(" type").toUpperC ase() ==
"SUBMIT") {
objRef.childNod es[i].setAttribute(" disabled", "true")
}
// ...and rename input fileds.
if (objRef.childNo des[i].nodeName.toUpp erCase() == "INPUT" &&
objRef.childNod es[i].getAttribute(" name").toUpperC ase()=="CUSTOME R"){
objRef.childNod es[i].setAttribute(" disabled", "true")
objRef.childNod es[i].setAttribute(" value", "test")
//THIS DOES NOT WORK
objRef.childNod es[i].setAttribute(" name", "customer1" )
}
// ...and rename input fileds.
if (objRef.childNo des[i].nodeName.toUpp erCase() == "INPUT" &&
objRef.childNod es[i].getAttribute(" name").toUpperC ase() ==
"FR_DATE"){
objRef.childNod es[i].setAttribute(" disabled", "true")
objRef.childNod es[i].setAttribute(" value", "test")
//THIS DOES NOT WORK
objRef.childNod es[i].setAttribute(" name", "from_date1 ")
}
if (objRef.childNo des[i].childNodes.len gth > 0) {
resetRow(objRef .childNodes[i])
}
}
I works ok. In the new row i can set the value of input elements,
disable the input element but not change the name of the input
elements. Why is this ?
If anybody can see this i will be one happy++
Tim
Comment