Re: Load Body html on button click.



Hi, Instead of using cookies.

I am using a database to store the elements on form.
And at body load I am reading the elements from database.
The only problem is when I am reading the elements I am attaching the
onclick event to the buttons on form. whenever i click any button on
form, it refer to the value of last element. So all the button clicks
open a same link.
and when i pass parameter to the function that i am attaching with
onclick event & when i load the page. the link opens automatically.

Is there a way to detect which button was clicked & the link dont open
automatically on page load.
Here is the code so far:
while(!RS3.eof) {
if (!document.getElementsByTagName('mytable')) return;
var tbl = document.getElementById('mytable');
tabBody=document.getElementsByTagName("TBODY").item(0);
var lastRow = tbl.rows.length;
var iteration = lastRow;
//alert(iteration);
row=document.createElement("TR");
cell1 = document.createElement("TD");
cell2 = document.createElement("TD");
textnode1=document.createElement('input');
textnode1.type = RS3.fields(3).value;
textnode1.name = RS3.fields(1).value;
textnode1.id = RS3.fields(2).value;
textnode1.size = RS3.fields(4).value;
textnode1.value = RS3.fields(5).value;

textnode[RS3.recordcount]=document.createElement('input');
textnode[RS3.recordcount].type = RS3.fields(8).value;
textnode[RS3.recordcount].name = RS3.fields(6).value;
var onClickname = "'" + RS3.fields(6).value + "'";
textnode[RS3.recordcount].id = RS3.fields(7).value;
textnode[RS3.recordcount].width = RS3.fields(9).value
textnode[RS3.recordcount].value = RS3.fields(10).value;
cell1.appendChild(textnode1);
cell2.appendChild(textnode[RS3.recordcount]);
row.appendChild(cell1);
row.appendChild(cell2);
tabBody.appendChild(row);
RS3.MoveNext();
textnode[RS3.recordcount].attachEvent('onclick',openWindow2);
}
}

function openWindow2(linkURL,elmClicked)
{
//alert(textnode1.value);
//var abc = '"' + textnode1.value + '"'
//if (window.event.srcElement == elmClicked)
//{
var abc = '"' + textnode1.value + '"'
window.open(eval(abc));
//alert(document.body.innerHTML);
//}
}
.


Quantcast