Click to See Complete Forum and Search --> : adding rows to a table and more....


stpaulmn
05-04-2006, 08:55 AM
My code to add rows to a table:

function addRow(){

var tbody = document.getElementById("table1").getElementsByTagName("tbody")[0];
var row = document.createElement("TR");
var cell1 = document.createElement("TD");
cell1.innerHTML = "MatterID";
//cell1.innerHTML = gRowId;

var cell2 = document.createElement("TD");
var inp1 = document.createElement("INPUT");
inp1.setAttribute("type","text");
inp1.setAttribute("value","");
inp1.setAttribute("size","60");
inp1.setAttribute('id','matterId');
inp1.setAttribute('name','matterId');
cell2.appendChild(inp1);


var cell3 = document.createElement('TD');
var inp2 = document.createElement('INPUT');
inp2.setAttribute('type','button');
inp2.setAttribute('value','LookUp');
inp2.onclick=function(){popupOpenSearchDialog();}
cell3.appendChild(inp2);


var cell5 = document.createElement('TD');
var inp4 = document.createElement('INPUT');
inp4.setAttribute('type','button');
inp4.setAttribute('value','Delete');
inp4.onclick=function(){deleteRow(this);}
cell5.appendChild(inp4);

row.appendChild(cell1);
row.appendChild(cell2);
row.appendChild(cell3);
row.appendChild(cell5);
tbody.appendChild(row);
//alert(row.innerHTML);
gRowId++;

cell1 = null;
cell2 = null;
cell3 = null;
cell4 = null;

row = null;
newRow = null;

tbody = null;

}

The popupOpenSearchDialog() will open a popup where i do a search.
There is a radio button, on click of which the selected row value should be inserted into the main window's MATTERID INPUT TEXT BOX. IT is only doing for the first time/first row..
Looks like it is losing the reference to the text box once the pop up is opened and I am using the following code to write the value into the text box in the main window frm the popup

Function in the popup to write into the text box of the main window:
function loadSelectedValue(matterId,matterName){
alert("matterId====" + matterId);
alert("matterName====" + matterName);
window.opener.document.forms[0].matterId.value = "(" + matterId + ")" + " -" + matterName;
alert("matteridname===" + window.opener.document.forms[0].matterId.value);
window.opener.focus();
window.close();

}

When i alert the values here in the popup all the values are dispayed correctly. I think I am not using the right way to put the value into the main window's text box.

Thankyou fo ryour help in advance

sridhar_423
05-04-2006, 09:10 AM
var tbody = document.getElementById("table1")[0].getElementsByTagName("tbody")[0];

stpaulmn
05-04-2006, 09:14 AM
thanks for your response...

are you asking me to change my tbody var to the one you have given?
it is giving me object required error if i change it!

sridhar_423
05-04-2006, 09:28 AM
very sorry.. overlooked the sentence.. thought u were using getElementsByTagNames.
will look into it and let you know if i find any solution/ bug ..

sridhar_423
05-04-2006, 09:38 AM
u might be calling the addrow function for more than time. hence the matterid element is being created for more than time. which becomes an array.
what i suggest you to do is to create one counter variable and append it to the matterid variable and pass that variable while calling your pop up window function

stpaulmn
05-04-2006, 12:52 PM
sridhar, followed ur rule and got it fixed!
thanks very much!

stpaulmn
05-04-2006, 12:54 PM
here is the changed code if anybody needs it!

Main Window:
gRowId=1; (this shld be declared outside the function)
var cell2 = document.createElement("TD");
var inp1 = document.createElement("INPUT");
inp1.setAttribute("type","text");
inp1.setAttribute("value","");
inp1.setAttribute("size","60");
inp1.setAttribute('id','matterId['+gRowId+']');
//inp1.setAttribute('name','matterId');
cell2.appendChild(inp1);

function popupOpenSearchDialog() {

document.applyMultiForm.rowID.value =gRowId;
alert("rowID===" + document.applyMultiForm.rowID.value);
var strOpt="width=600,height=700,menubar=no,personalbar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no";
win = window.open("jsp/relatedMatterPopupTWO.jsp","",strOpt);

//var url = "jsp/relatedMatterPopupTWO.jsp?";
//url += "&gRowId=" + gRowId;
//win = window.open(url,"",strOpt);
//win = window.open("jsp/relatedMatterPopup.jsp");
win.focus();
}

Popup window code:
function loadSelectedValue(matterId,matterName){
alert("matterId====" + matterId);
alert("matterName====" + matterName);

var rowID=window.opener.document.getElementById("rowID").value;
alert("rowID==" + rowID);
rowID=rowID-1;
var el = window.opener.document.getElementById('matterId['+rowID+']');
el.setAttribute("value","(" + matterId + ")" + " -" + matterName);
alert("e1-===" + el.value);
window.opener.focus();
//window.opener.document.getElementById('matterId')[gRowId].focus();
window.close();

}