I have a yes radio input. When the user clicks yes, yesDiv is displayed, and when the user does not click no, noDiv is displayed.
To implement this, I created myObject.
var myObject= {
init: function(config){
this.config=config;
this.config.InputRadio.bind('click',this.config,this.switchDiv);
},
switchDiv: function(ev){
self=ev.data;
if ($(this).val()==1){
self.divYes.hide();
self.divNo.show();
}else{
self.divYes.show();
self.divNo.hide();
}
}
}
myObject.init({
InputRadio:$("input[name=yesno]"),
divYes:$("#yesDiv"),
divNo:$("#noDiv")
});
This works, I know that I cannot use this to refer to the properties of an object inside the 'switchDiv' method due to the scope of the 'this' inside the function. I found a solution to send this.config as a parameter, and then using self = ev.data in a related question ( Link to the object’s own properties .)
: , , , ? , ?