When you specify a function (with or without parameters) in the DOM via onChange, you are limited to static paramters. E.g.
<select id="blah" onChange="doSomething(3);">
However, jQuery lets you dynamically define and assign functions to event handlers, such as 'change'.
See the example below:
function addRow(customObject) {
<< Create TR containing a select named "#someSelect + customObject.id" >>
// Demo
$("#someSelect" + customObject.id).change(function() {
changeSomething(customObject)
});
}
My question is - essentially - will this work? I am using a specific instance o f an object in my jQuery change event handler. Will that particular instance of customObject (wherever it lies) always be bound to this event handler callback?
customObject is initialized at load, and is one of many. For that particular select box, I always want it to be linked to that object.
New to jQuery. Thanks in advance.
EDIT:
I have several rows of items. Each is represented by an object. I just want to make sure that when someone modifies one of the rows via HTML, that the underlying object (bound to the callback function) is properly updated.
I am looking for something like this, conceptually a mapping between:
Row 1 - customObject1
Row 2 - customObject2
Row 3 - customObject3
... such that if I modify one of the HTML elements (e.g. change the select box) in row 3, that behind the scenes, customObject3 is modified
customObject.idequals (for instance) 2 and you have an element with idsomeSelect2, then yes, it will "work". But I'm not sure it will do what you're expecting, as I can't really make out what exactly it is that you're ultimately trying to accomplish here.