473,758 Members | 2,340 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting a method's name

Here's my situation. I have an object
function Obj () {
this.foo = null;
}

a function
function bar() {...}

another function

function doSomething () {
var obj = new Obj();
obj.foo = bar;
doSomethingElse (obj);
}

In function doSomethingElse I want to create the following line of DHTML

<div onClick="obj.fo o(); return true;">
What I want is for onClick to be defined to be the execution of the foo
method of obj.

I tried document.writel n ("<div onClick='" + obj.foo + "(); return
true;'>");
What I get is the source code for bar stuck into the middle of the string.
So how do I get just the name of the function bar in the string? Or
ultimately, how do I get the handler to be bar in the DHTML?

Thanks.

Ken
Jul 23 '05 #1
6 1862
Lee
Ken Kast said:
In function doSomethingElse I want to create the following line of DHTML

<div onClick="obj.fo o(); return true;">
What I want is for onClick to be defined to be the execution of the foo
method of obj.

I tried document.writel n ("<div onClick='" + obj.foo + "(); return
true;'>");
There's no trick to it. It's just a string;

document.writel n('<div onclick="obj.fo o();return true;">');

What I get is the source code for bar stuck into the middle of the string.
So how do I get just the name of the function bar in the string? Or
ultimately, how do I get the handler to be bar in the DHTML?


document.getEle mentById("theId AttributeOfYour Div").onclick=o bj.foo;

Jul 23 '05 #2
But obj.foo won't be defined when that line of HTML is parsed. I
essentially need to convert the "relative" (to the script) ref to obj.foo to
an "absolute" ref to bar when the browser sees the HTML coming in via the
writeln statement.

Ken
"Lee" <RE************ **@cox.net> wrote in message
news:cb******** @drn.newsguy.co m...
Ken Kast said:
In function doSomethingElse I want to create the following line of DHTML

<div onClick="obj.fo o(); return true;">
What I want is for onClick to be defined to be the execution of the foo
method of obj.

I tried document.writel n ("<div onClick='" + obj.foo + "(); return
true;'>");


There's no trick to it. It's just a string;

document.writel n('<div onclick="obj.fo o();return true;">');

What I get is the source code for bar stuck into the middle of the string.So how do I get just the name of the function bar in the string? Or
ultimately, how do I get the handler to be bar in the DHTML?


document.getEle mentById("theId AttributeOfYour Div").onclick=o bj.foo;

Jul 23 '05 #3
Lee
Ken Kast said:

But obj.foo won't be defined when that line of HTML is parsed. I
essentially need to convert the "relative" (to the script) ref to obj.foo to
an "absolute" ref to bar when the browser sees the HTML coming in via the
writeln statement.


Then the correct solution depends on what you're actually
trying to accomplish, and probably involves either global
variables.

Jul 23 '05 #4
"Ken Kast" <ke*@NOSPAMkenk ast.com> writes:

....
function doSomething () {
var obj = new Obj();
obj.foo = bar;
doSomethingElse (obj);
}

In function doSomethingElse I want to create the following line of DHTML

<div onClick="obj.fo o(); return true;">
What I want is for onClick to be defined to be the execution of the foo
method of obj.
Then this won't work.

At this point of the execution, the only reference to the object is
the first parameter of the doSomethingElse function.

What you want to write is a way to reference that value from the global
scope (where the intrinsic event handler is executed).

To do that, you must make a globally available reference to the object.
Say:
window.xyzzy = arg1; // or whatever the parameter is called
document.writel n ("<div onclick='window .xyzzy(); " +
"return true;'>");
I tried document.writel n ("<div onClick='" + obj.foo + "(); return
true;'>");
What I get is the source code for bar stuck into the middle of the string.
Yes. I am not sure you realize that you are building syntax here. There
is no way for the syntax to carry an actual reference to the object. At
best it can contain syntax that evaluates to such a reference, but only
if such a reference is available at all in the scope where the code is
executed.
So how do I get just the name of the function bar in the string?
You don't want the name (it's "bar"). You want a Javascript expression
(syntax) that, when evaluated as an intrinsic event handler, evaluates
to a reference to the existing object.
Or ultimately, how do I get the handler to be bar in the DHTML?


Make a global reference with either a fixed or a computed name,
and then use that in the syntax you write.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #5
Ken Kast wrote:
Here's my situation. I have an object
function Obj () {
this.foo = null;
}

a function
function bar() {...}

another function

function doSomething () {
var obj = new Obj();
obj.foo = bar;
doSomethingElse (obj);
}

In function doSomethingElse I want to create the following line of DHTML

<div onClick="obj.fo o(); return true;">
What I want is for onClick to be defined to be the execution of the foo
method of obj.

I tried document.writel n ("<div onClick='" + obj.foo + "(); return
true;'>");
What I get is the source code for bar stuck into the middle of the string.
So how do I get just the name of the function bar in the string? Or
ultimately, how do I get the handler to be bar in the DHTML?

Thanks.

Ken

Have a look at this:

// "The following example uses a small generalised closure based function
// that associates object instances with element event handlers."
// http://jibbering.com/faq/faq_notes/closures.html#clObjI
Jul 23 '05 #6
Actually, I found a simple solution by searching this group. I create
a property bar.name="bar". In my DHTML I use obj.foo.name and it
works hunky-dory.

Ken

Lasse Reichstein Nielsen <lr*@hotpop.com > wrote in message news:<ll******* ***@hotpop.com> ...
"Ken Kast" <ke*@NOSPAMkenk ast.com> writes:

...
function doSomething () {
var obj = new Obj();
obj.foo = bar;
doSomethingElse (obj);
}

In function doSomethingElse I want to create the following line of DHTML

<div onClick="obj.fo o(); return true;">
What I want is for onClick to be defined to be the execution of the foo
method of obj.


Then this won't work.

At this point of the execution, the only reference to the object is
the first parameter of the doSomethingElse function.

What you want to write is a way to reference that value from the global
scope (where the intrinsic event handler is executed).

To do that, you must make a globally available reference to the object.
Say:
window.xyzzy = arg1; // or whatever the parameter is called
document.writel n ("<div onclick='window .xyzzy(); " +
"return true;'>");
I tried document.writel n ("<div onClick='" + obj.foo + "(); return
true;'>");
What I get is the source code for bar stuck into the middle of the string.


Yes. I am not sure you realize that you are building syntax here. There
is no way for the syntax to carry an actual reference to the object. At
best it can contain syntax that evaluates to such a reference, but only
if such a reference is available at all in the scope where the code is
executed.
So how do I get just the name of the function bar in the string?


You don't want the name (it's "bar"). You want a Javascript expression
(syntax) that, when evaluated as an intrinsic event handler, evaluates
to a reference to the existing object.
Or ultimately, how do I get the handler to be bar in the DHTML?


Make a global reference with either a fixed or a computed name,
and then use that in the syntax you write.
/L

Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1807
by: Willoughby Bridge | last post by:
Hi - Having trouble getting a multipart series of forms to move to the next form. The problem line is: <form method="post" enctype="multipart/form-data" action="Data_Form1.php"> If the "action" parameter is set to the current form (Data_Form1.php) then the data posts to the table correctly, but it does not move to the next form If the "action" parameter is set to the next form in the series then by clicking "submit" it moves to the...
2
6928
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on a type mismatch. It is positively because of the boolean(java primitive)parameter. It goes fine if I change this parameter to int or String. This inteface has a lot more methods which works fine, it is just the
6
22532
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object instance (in this case 'myDog'). Of course it would be better if I could somehow know from within write() that the name of the object instance was 'myDog' without having to pass it as a parameter. //////////////////////////////// function...
4
4938
by: gimme_this_gimme_that | last post by:
Hi, This is sort of a : How to build a Yes/No dialog box qquestion. Or perhaps a question about getting javascript variables from a pop-up window and processing them on a submit. This is what I'd like to have happen :
0
1756
by: Erik | last post by:
Why isn't my update method getting called? Pasted below is an aspx from a 1.1 application I'm working on. It has two textboxes and a button for inserting data into the database, and a datagrid for editing and deleting data. When a user clicks on the "Edit" button in the datagrid, Edit() method is called and the appropriate row is changed into textboxes. And if user clicks on the "Update" button, the Update() method is fired. But if...
1
9483
by: kamleshsharmadts | last post by:
I am using Ajax with struts in web application. from jsp i am calling a function of ajax.js onclick of a button. code of that call function which calling from jsp given as below:- onclick="retrieveURL('/application/home_page.do?processAction=ItinerarySearch','AfoHomeForm')" after clicking on button i am getting following error:- object does not support this property or method at statement (Which i have made it bold in js file)
0
1181
by: Steve | last post by:
Hi All, I have a Python script that uses SOAPpy and I'm outputting all of the methods and info about the parameters... I'm having trouble getting information out of the __init__ parameter. My code : from SOAPpy import WSDL
2
6658
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double) Location: class Week5MortgageGUI Week5MortgageLogic allint = logic.allInterest(amount, term, rate); Week5MortgageGUI.java:152:cannot find symbol symbol: method allInterest(double,double,double) Location: class Week5MortgageGUI
21
3897
vikas251074
by: vikas251074 | last post by:
I am getting error while entry in userid field. When user enter his user id, an event is fired immediately and user id is verified using AJAX method. But I am getting error 'Object doesn't support this property or method'. <form name="myform" action="main.asp" method="post"> <div id="content"> <h2 id="pageName">Main Page</h2> <div class="feature"> <h1>Surfing the intranet </h1> <p> This is a comprehensive information...
7
4701
by: Andrus | last post by:
How to get syntactically correct signature which compiles for code template grneration ? I tried code below but it creates syntactically incorrect signature. Andrus. using System; using System.Collections.Generic; public class MainClass
0
9492
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10076
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9908
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7287
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3402
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2702
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.