I am trying to attach a callback function into the onclick attribute of an HTML input button. The catch is, I have to pass in the value of a variable from outside the callback.
Here's the code (edited for length... might have left out a paren or semicolon):
This onclick is supposed to dynamically remove a row from a table.. the table has an ID of "itemTable", and the row has a dynamic id with "-row" appended. However, I cannot seem to successfully pass jId's value into the function... jId gets put in literally.
Since the row's ID is dynamic, I have to pass the parameter.
Jason [ January 22, 2008: Message edited by: Eric Pascarello ]
You are not passing jId. You are declaring that the the first parameter to the function that you are declaring will be named jId in the body of the function. This has no relation to the jId declared outside the function.
As Eric pointed out, the standard way to deal with this is to rely upon closures. [ January 22, 2008: Message edited by: Bear Bibeault ]
Joined: Aug 09, 2007
Unfortunately, I think I'm looking at something akin to a scoping error. Thanks to Firebug, I know that the generated HTML for the input button looks like this:
(Note: the forum would not let me use "onclick"... its not a typo).
Maybe under "normal" circumstances, closures would take care of this, but since the button has the function inlined, it's not working correctly.
Also, Builder refers to script.aculo.us's Builder object which can automagically build DOM elements. I don't know the best solution to my problem, unfortunately.