jxbma
asked on
Why is my onclick event on row <tr> throws "is not defined exception in HTML5/jquery?
Hi:
I'm trying to get the onclick event working in a <tr>
I create <tr>s and add the to my table in javascript.
When I click on the row at runtime, I get the following error.
Both of the above functions are defined with the same JS file, so scope should not be an issue (I think).
Any ideas would be helpful here. I think I need to pass the "this" so that I'll be able to tell which row was actually clicked. I can then get the required data from the row.
Any advice/thoughts on this?
I'm trying to get the onclick event working in a <tr>
I create <tr>s and add the to my table in javascript.
function LoadTheCodeOnDemand(){
function ClickGeneratedOrderRow(orderRow){
alert("Clicked on Row");
};
function AddARow(){
tableRow = $('<tr onclick="ClickGeneratedOrderRow(this);"/>');
// Add a bunch of <td>s to the row
$('#GeneratedOrdersTable > tbody').append(tableRow);
};
};
When I click on the row at runtime, I get the following error.
(function() {with (this[2]) {with (this[1]) {with (this[0]) {return function(event) {ClickGeneratedOrderRow(this);
Uncaught Reference Error: ClickGeneratedOrderRow is not defined.
Both of the above functions are defined with the same JS file, so scope should not be an issue (I think).
Any ideas would be helpful here. I think I need to pass the "this" so that I'll be able to tell which row was actually clicked. I can then get the required data from the row.
Any advice/thoughts on this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Segdwick should have set the point: each function must be declared separately inside the script definition.
ASKER
We are integrated with Spring. Declaring functions within a DemandLoadPage() function allows me to package functions in a separate JS file which then get loaded only when the requested page is loaded into the browser.
(I didn't design the overall architecture here, so I'm not in a position to change it either).
JB
(I didn't design the overall architecture here, so I'm not in a position to change it either).
JB
ASKER
This works.
I created an Object outside of the scope of the demand load function.
I assigned the function as "a method" on that object.
I then was able to call it via "ScopeObject.ClickGenerate dOrderRow( this)".
All is well,
Thanks,
JB
I created an Object outside of the scope of the demand load function.
I assigned the function as "a method" on that object.
I then was able to call it via "ScopeObject.ClickGenerate
All is well,
Thanks,
JB
Open in new window