View Full Version : How can I create a link tag and and assign LoadSupplierProductsGrid to onlick dynami

03-11-2012, 01:21 AM
How can I create a link tag and and assign LoadSupplierProductsGrid to its onlick dynamically in javascript?

My Function should be like the following:
LoadSupplierProductsGrid(ParameterA, ParameterB)

I have done it with 1 “ParameterA” but having difficulties creating it with 2 parameters.

"<a href='javascript:void(0);' onclick='LoadSupplierProductsGrid(" + ParameterA + ")'>" + ReportRSet.getfieldbyname(i, "Company Name") + "</a>";

03-11-2012, 09:57 AM
How about that?

"<a href='javascript:void(0);' onclick='LoadSupplierProductsGrid(" + ParameterA + ", " + ParameterB + ")'>" + ReportRSet.getfieldbyname(i, "Company Name") + "</a>";

If that doesn't work you'll have to think about how exactly(!) the resulting code should look like. Depending on the type of the parameter, you can have something like

LoadSupplierProductsGrid(ContentOfParameterA, "ContentOfParameterB")

03-11-2012, 12:17 PM
Use DOM to create the link and then assign an onclick handler

var link = document.createElement('a');
link.href = "#";
link.innerHTML = ReportRSet.getfieldbyname(i, "Company Name");
link.paramA = ParameterA;
link.paramB = ParameterB;
link.onclick = function() {LoadSupplierProductsGrid(this.paramA, this.paramB); return false;}
//then append link to its parent
I'm assuming that this block of code is inside a loop and ParameterA and B have different values for each iteration.