How Do I Access The Object Instance From Within Class
Apr 22, 2007
I have a javascript object which dynamically generates a table adding, deleting and moving rows as the user clicks on buttons or links. Problem is when I generate a table row and add the javascript method call to my class, I have to put the object instance name variable of the class in order for it to be called from the onclick=function(). This is seriously limiting, but I'm stuck for a way round it. Heres a edited of the code so you get the idea....
Instantiating the object :-
var dtl = new DynamicTableList("table1", $
{myObject.allFieldsAsJavaScriptArray}, true, true, true);
My javascript class DynamicTableList, note the dtl javascript object
instance variable being referred to in the addRow function. How can I
avoid this???
function DynamicTableList(thisObjName, tableName, options, showDelete,
showUp, showDown)
{
this.processRow = function(r, row, up, down)
{
...
};
this.processRows = function()
{
...
};
this.getVisibility = function(visible)
{
...
};
this.delRow = function(button)
{
...
};
this.addRow = function(selection)
{
...
if (showDelete)
{
var cell2 = document.createElement('TD');
var inp2 = document.createElement('IMG');
/
************************************************** ***********************************************/
inp2.onclick=function(){dtl.delRow(this);} // Have to specify
dtc!!!!!!!!
/
************************************************** ***********************************************/
inp2.title='Delete'
inp2.alt='Delete'
inp2.src='images/delete.gif'
cell2.appendChild(inp2);
row.appendChild(cell2);
}
...
tbody.appendChild(row);
this.processRows();
};
this.moveRow = function(node, vector)
{
};
}
Obviously the code dtl.delRow(this); is being dynamically generated, but how do I replace the dtl instance name with something that'll work whatever the user of this class calls the instance of it!
View 2 Replies
ADVERTISEMENT
Mar 17, 2007
I have a String instance which contains the name of a class. Is there some way I can instantiate that class from given the class name in the string?
View 4 Replies
View Related
Dec 14, 2009
I need to change the background-image (or possibly background-position) property of each new instance of a div with a particular class. I will have a set of images to choose from, or could create a sprite with all of the images.
Example:
Code:
<div class="desc">content</div> **needs background-image: url(pic1.jpg)
<div class="desc">content</div> **needs background-image: url(pic2.jpg)
...
etc.
The page code is dynamically generated from our CMS, so can't change the HTML.
View 3 Replies
View Related
Sep 6, 2010
Basically I have this code:
Code:
<div id="rightNews">
<div class="showHead">
<a href="#" class="showAcc">7th July 2010</a><br />
Lorium epsom diem Lorium epsom diem Lorium epsom diem
[Code]....
But when I click to expand one coloumn all of them expand as they have the same class, is there a way so the others close when another one is clicked?
View 2 Replies
View Related
Jun 15, 2010
I have the following style markup:
<h2>
<span class="status">
UNDER OFFER
</span>
[Code].....
As i'm trying to add an overlay image to the hyperlink so it will appear on top of the image that is already there (css absolute and z-index).
View 5 Replies
View Related
Nov 17, 2011
I have a large number of "li"s with the same class - i.e;
<li class="month01Days"></li>
:
:
[code]....
View 1 Replies
View Related
Dec 17, 2005
I'm trying to use a variable that is passed into a function to to dynamically name an instance of an Object(). I've created a Timer() Object that seems to work just fine... the problem is I can't figure out how to pass in an instance name into setTimer() to create a new instance of Timer() object?? My ultimate goal is to have multiple instances of the Timer() Object running at once. While the code below works it only allows me to create 1 instance of the Timer() Object with the name of tmp. Code:
View 8 Replies
View Related
Jun 8, 2011
I have made/modifying a script that I can create AJAX objects on the fly. It is working fine in Chrome, FF, Opera, Safari but not IE -.- IE = nightmare
[Code]...
View 1 Replies
View Related
Jan 3, 2006
I've been playing around with JS for a while, but I've not ever found fantastic learning resources. I'm comfortable with other programming languages, so I'm very interested in OOP programming for JS, and I've started to use tools like the Prototype library for that purpose.
However, one problem has consistently caused me problems whenever I'm writing a JS Class. How can I get a reference to the specific class instance from inside an event handler that I create with a class method. Let me give an example of what I want to do:
(This code is using the Prototype library...)
myClass = Class.create();
myClass.prototype = {
makeLink: function(obj) {
// Out here, "this" refers to the instance of the myClass Class
obj.innerHTML = ''
obj.onclick = function() {
// In here, "this" refers to the clicked on element.
// How do I get a reference to the instance of myClass in here?
}
}
Here's the best way that I know how to do this right now. It seems to work in Firefox alright, but doesn't seem to work in IE:
myClass = Class.create();
myClass.prototype = {
makeLink: function(obj) {
obj.innerHTML = ''
self = this; // Save a reference to class instance as "self"
obj.onclick = function() {
// Self is evaluated to instance reference at time of assignment to onclick
self.linkClicked();
}
linkClicked: function() {
// Do something useful here
}
}
Is there a more elegant way to do this? I could just create all of my event handlers for objects outside of the class in procedural code where I already have a reference to the class object, but I like to wrap these things up inside the class, because sometimes they get significantly more complicated than this very simple one. Anybody have any solutions? This has to be a common design pattern...
View 8 Replies
View Related
Mar 10, 2011
I am trying some simple things with javascript and trying to use it in a object oriented way. However I am now facing a problem in which I can't access an object variable from an object method. I am using jQuery.
My code is as follows;
Code:
My problem is that the variable msg1 does not work when accessed from function called from the jQuery get function. I get the message undefined. Therefore I am wondering, is there a way how I can access msg1 of my object instance from the get function of jQuery?
View 1 Replies
View Related
Mar 7, 2008
How do we access class names?
For example, this code...
If you want to parse html and find the title element you can find the class name "the-title". That's what I am trying to do.
How do I do that?
View 7 Replies
View Related
Nov 23, 2011
How can I access class name without using id. I have following div tag:
<div class="aa bb cc">
</div>
Their are three classes if I access class then which one will be access.
View 1 Replies
View Related
Sep 12, 2010
I was wondering how to access parents class variable. For example:
Code:
function Class(){
this.variable; }
SubClass.prototype = Class;
SubClass.prototype.constructor = SubClass;
function SubClass(){
this.secondVariable = Class.variable; <-how to access parent variable?
}
View 2 Replies
View Related
Feb 7, 2011
I have UL tag:
<ul id='ul'>
<li id='li1' class='someclass'>
li1</li>
<li id='li2' class='someclass'>
[Code]....
Now we have alerts only for three old elements. This is clear. Because these elementes have been initiated before page generated. But the new one is ignored.
The question is - how i can add new elements to the UL list? It would be glad if "jQuery.each" could read four and more elements - not just the first three initiated elements.
View 1 Replies
View Related
Jan 20, 2010
I have 95 different objects like this one:
obj1Object = {
name: "some name",
type: "type",
picid: "001",
maxvl: 500000,
minvl: 5000,
clsid: 1,
movable: true,
size: [45, 45],
note: "Some text here"
}
Now what I need is to access these objects only when I need then. Right now they all load when accessing my program so all 95 of them are "somewhere" in memory.
View 3 Replies
View Related
Aug 13, 2010
I have a html file with javascipt embeded in, in this file I want to use a table object in another javascript file. How do I access this object?
View 2 Replies
View Related
Jul 23, 2005
I want to access the features of a plugin without actually embedding
it into a page. Is this possible? Eg
The code to embed the object into a page is:
<OBJECT classid='CLSID:7FA62735-AHC3-14d2-9F81-00114B3245C5
codebase='http://www.test.com/plug.cab#version=3,1' "id='myPlugin'
height=Ɔ' width=Ɔ'>
<EMBED type='application/x-myPlugin' name='myPlugin' hidden='true'
src='in.txt'></EMBED>
</OBJECT>
I could simply add this using document.write, but for various reasons
I dont want to do this.
I would rather do something like:
var plugin = (navigator.mimeTypes &&
navigator.mimeTypes["application/x-Web-Plugin"]) ?
navigator.mimeTypes["application/x-Web-Plugin"].enabledPlugin : 0;
myObj = new object("CLSID:7FA62735-AHC3-14d2-9F81-00114B3245C5");
myObj.pluginMethod
View 2 Replies
View Related
Jul 20, 2005
Assume a form with a button
<form id="myform"
<input id="mybutton" type="button">
</form>
how can i use getElementById to access the button?
I tried this: var a
a=document.getElementById("mybutton")
but i get an error "a is not an object"
Any idea?
View 2 Replies
View Related
Mar 17, 2011
i have function appended to a click event of more than one objects. How can i check if the object that was clicked has a certain class xy?
var t = jQuery(this);
jQuery(t.children()).click(function(e) {
if (??check if the element that was clicked has class xy??){}
}
View 3 Replies
View Related
Oct 11, 2010
I've created an object with properties and methods. The object is associated with a form. The object iterates through the form and finds any inputs that are required. It then uses each to apply validation to each of the found inputs. From within each(), I need to access properties and methods of the parent object, but now this refers to the current collection object. How do I access the containing object?
View 1 Replies
View Related
Jul 14, 2009
If "this" inside of a sortable "receive" function refers to the receiving object, How do I access the object to which the receive function belongs?
Example:
// Function that takes a JQ object and makes it sortable.
// We assign the "SortableRecieve" method to the receive event
MyObject.prototype.MakeSortable = function(JQOBJ){
JQOBJ.sortable({
receive: this.SortableRecieve
});}
MyObject.prototype.DoSomething = function(){
// Does something important
}
// The actual function that gets called when the receive event occurs
MyObject.prototype.SortableRecieve = function(event, ui){
// This function call won't work, because "this"
// doesn't point to the right thing!
this.DoSomething();
}
So how can I access the "True" this that refers to the object?
View 2 Replies
View Related
May 6, 2010
I have very simple question (ie probably simple for everyone with jQuery experience, but not for me). Lets say I have the following list
<div>
<li id="first"><a>one</a></li>
<li><a>two</a></li>
<li><a>three</a></li>
<li><a>four</a><li>
</div>
Now, if I want to get all the list items after the first, and change the text within the anchor tags, if a certain condition is met (eg change to capitals if it starts with a "t"). How can I do that? My approach was to get all the list items (after the first) with
[Code]...
View 1 Replies
View Related
Apr 1, 2011
I am fairly familiar with the concept of Objects and their properties and methods, but javascript being object based as opposed to object oriented has me stumped on how to access an object's properties from an onclick event handler created for another object created within the original object.
In the example below, I have a constructor function called anyObj. to which I pass an object reference to an element.
anyObj has 3 properties and one function increaseWidth()
increaseWidth() creates a new button with an onclick event handler and this is where I have a problem.
The onclick function needs to increase the value of anyObj's this.width property. I originally had a line this.width += 10; in the onclick but quickly realised why this wasn't working because the this in the onclick function refers to the new button object and not the this.width property of anyObj.
The workaround I have used, and it works, is to make a copy of all the this.xxxxx properties. eg. width = this.width; and use the width variable in the onclick as you can see below. This "workaround" works fine but doesn't feel ideal to me.
So is there a better way to access the anyObj()'s properties from within the onclick function than the way I have done it? Obviously I would prefer to not have to make copies of all the anyObj() properties like I have to make them accessible to the onclick function.
function anyObj(divObj){
this.elem = divObj;
this.width = 50;
this.height = 50;
[Code]....
View 5 Replies
View Related
Jun 15, 2011
I have a JS method register in a TD element as below:
Below is the Js Method:
The JS method works fine in IE but in mozilla throws an error that event is undefined.
I cant pass the event object from HTML while registering the method as HTML is written by someone else and I cannot change that. All I can change is the JS method.
How can i access the event object in JS method.
View 9 Replies
View Related
Mar 25, 2006
I've created an object and within this object, I've added an eventlistener. But the problem now is that after addEventListener is being called to access a callback function, the callback function is not able to access the properties within its own class. Code:
View 14 Replies
View Related
Sep 30, 2007
I have a page (page 1), my page 1 has an IFRAME which loads another page (page 2).
My page 2 has a JavaScript object declared on the page: var MyObject = new Object();
I want to access this object from the parent page (page 1).
I tried:
var TempObj = document.getElementById("MyIFrame");
TempObj.document.MyObject.value = "blah blah";
But it said MyObject didn't exist.
Can someone tell me how to access it in this manner?
View 2 Replies
View Related