T
timmy_dale12
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(baseRowId, tableId) {
// Get a reference to the base row.
var baseRow = document.getElementById(baseRowId)
// Clone the base row.
var newRow = baseRow.cloneNode(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.getElementById(tableId).lastChild.appendChild(newRow)
}
function resetRow(objRef) {
for (var i = 0; i < objRef.childNodes.length; i++) {
// Reset ONLY input elements (NOT checkboxes or submit/reset
buttons)...
if (objRef.childNodes.nodeName.toUpperCase() == "INPUT" &&
objRef.childNodes.getAttribute("type").toUpperCase() !=
"CHECKBOX" &&
objRef.childNodes.getAttribute("type").toUpperCase() !=
"SUBMIT" &&
objRef.childNodes.getAttribute("type").toUpperCase() !=
"RESET") {
objRef.childNodes.setAttribute("value", "")
}
// ...and DISABLE submit buttons.
if (objRef.childNodes.nodeName.toUpperCase() == "INPUT" &&
objRef.childNodes.getAttribute("type").toUpperCase() ==
"SUBMIT") {
objRef.childNodes.setAttribute("disabled", "true")
}
// ...and rename input fileds.
if (objRef.childNodes.nodeName.toUpperCase() == "INPUT" &&
objRef.childNodes.getAttribute("name").toUpperCase()=="CUSTOMER"){
objRef.childNodes.setAttribute("disabled", "true")
objRef.childNodes.setAttribute("value", "test")
//THIS DOES NOT WORK
objRef.childNodes.setAttribute("name", "customer1")
}
// ...and rename input fileds.
if (objRef.childNodes.nodeName.toUpperCase() == "INPUT" &&
objRef.childNodes.getAttribute("name").toUpperCase() ==
"FR_DATE"){
objRef.childNodes.setAttribute("disabled", "true")
objRef.childNodes.setAttribute("value", "test")
//THIS DOES NOT WORK
objRef.childNodes.setAttribute("name", "from_date1")
}
if (objRef.childNodes.childNodes.length > 0) {
resetRow(objRef.childNodes)
}
}
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(baseRowId, tableId) {
// Get a reference to the base row.
var baseRow = document.getElementById(baseRowId)
// Clone the base row.
var newRow = baseRow.cloneNode(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.getElementById(tableId).lastChild.appendChild(newRow)
}
function resetRow(objRef) {
for (var i = 0; i < objRef.childNodes.length; i++) {
// Reset ONLY input elements (NOT checkboxes or submit/reset
buttons)...
if (objRef.childNodes.nodeName.toUpperCase() == "INPUT" &&
objRef.childNodes.getAttribute("type").toUpperCase() !=
"CHECKBOX" &&
objRef.childNodes.getAttribute("type").toUpperCase() !=
"SUBMIT" &&
objRef.childNodes.getAttribute("type").toUpperCase() !=
"RESET") {
objRef.childNodes.setAttribute("value", "")
}
// ...and DISABLE submit buttons.
if (objRef.childNodes.nodeName.toUpperCase() == "INPUT" &&
objRef.childNodes.getAttribute("type").toUpperCase() ==
"SUBMIT") {
objRef.childNodes.setAttribute("disabled", "true")
}
// ...and rename input fileds.
if (objRef.childNodes.nodeName.toUpperCase() == "INPUT" &&
objRef.childNodes.getAttribute("name").toUpperCase()=="CUSTOMER"){
objRef.childNodes.setAttribute("disabled", "true")
objRef.childNodes.setAttribute("value", "test")
//THIS DOES NOT WORK
objRef.childNodes.setAttribute("name", "customer1")
}
// ...and rename input fileds.
if (objRef.childNodes.nodeName.toUpperCase() == "INPUT" &&
objRef.childNodes.getAttribute("name").toUpperCase() ==
"FR_DATE"){
objRef.childNodes.setAttribute("disabled", "true")
objRef.childNodes.setAttribute("value", "test")
//THIS DOES NOT WORK
objRef.childNodes.setAttribute("name", "from_date1")
}
if (objRef.childNodes.childNodes.length > 0) {
resetRow(objRef.childNodes)
}
}
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