473,385 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

indirect function calls

I am building repetitive forms using PHP and templates; the PHP loops
through the data and stuffs it into the templates. Javascript functions
then handle each entry field as required.... I am using elements in my
html that look like this:

<button tabindex=%t% id='a%t%' ptype='button'
imageList="/skip.png,/pause.png,/cw.png,/ccw.png" wrap="true"
valTarget='ha%t%' imageTarget='ia%t%'><img src='/skip.png'
id='ia%t%'></button>

where the ptype indicates which javascript function should handle that
particlular element.

So in this case it's a ptype of button.

My javascript key handler then does this:

function DoKey(step, dir) {
if (!activeElement.getAttribute('ptype'))
numericalField(step, dir);
else switch(activeElement.getAttribute('ptype')) {
case 'numerical':
numericalField(step, dir);
break;
case 'button':
buttonField(step, dir);
break;
case 'time':
timeField(step, dir);
break;
case 'date':
dateField(step, dir);
break;
}
}

I can't help but think that I should be able to do something like this:

(activeElement.getAttribute('ptype')+'Field')(step , dir)

to call the function directly... Is there a construct that works like
that or should I stick with the case construct?

Apr 21 '06 #1
4 2475
In a recent message, someone pointed out that all Javascript functions
are passed through the Window object, so you can do this:

function firstFunction(str) {
// do stuff
window[str]();

You should be able to apply this directly to your function.

Stan Scott
New York City

Captain Dondo wrote:
I am building repetitive forms using PHP and templates; the PHP loops
through the data and stuffs it into the templates. Javascript functions
then handle each entry field as required.... I am using elements in my
html that look like this:

<button tabindex=%t% id='a%t%' ptype='button'
imageList="/skip.png,/pause.png,/cw.png,/ccw.png" wrap="true"
valTarget='ha%t%' imageTarget='ia%t%'><img src='/skip.png'
id='ia%t%'></button>

where the ptype indicates which javascript function should handle that
particlular element.

So in this case it's a ptype of button.

My javascript key handler then does this:

function DoKey(step, dir) {
if (!activeElement.getAttribute('ptype'))
numericalField(step, dir);
else switch(activeElement.getAttribute('ptype')) {
case 'numerical':
numericalField(step, dir);
break;
case 'button':
buttonField(step, dir);
break;
case 'time':
timeField(step, dir);
break;
case 'date':
dateField(step, dir);
break;
}
}

I can't help but think that I should be able to do something like this:

(activeElement.getAttribute('ptype')+'Field')(step , dir)

to call the function directly... Is there a construct that works like
that or should I stick with the case construct?


Apr 23 '06 #2
st*****@gmail.com wrote:
In a recent message, someone pointed out that all Javascript
functions are passed through the Window object, so you can
do this:
If anyone did then they were making false statements. Only functions
declared in the global execution context would normally be properties of
the window object. Other functions may be explicitly assigned to
properties of the window/global object at runtime, though that would be
a generally unwise action to take.

<snip> Captain Dondo wrote:

<snip>

Please do not top-post to comp.lang.javascript.

Richard.
Apr 24 '06 #3
Captain Dondo said on 22/04/2006 4:38 AM AEST:
I am building repetitive forms using PHP and templates; the PHP loops
through the data and stuffs it into the templates. Javascript functions
then handle each entry field as required.... I am using elements in my
html that look like this:

<button tabindex=%t% id='a%t%' ptype='button'
imageList="/skip.png,/pause.png,/cw.png,/ccw.png" wrap="true"
valTarget='ha%t%' imageTarget='ia%t%'><img src='/skip.png'
id='ia%t%'></button>
If you want to show your HTML, then post the HTML that a browser
actually gets, not the PHP (or whatever) code that generates it. We'll
fix your client-side issues, how you generate your markup is deal with
in other news groups.

where the ptype indicates which javascript function should handle that
particlular element.
If you know the ptype when generating the page, then you should be able
to insert the correct function when that is done on the server, hence
you have a PHP (or whatever) issue, not a javascript issue.

The value of an HTML element's on<event> attribute is text that is
interpreted as script, so insert the name of the function directly.

So in this case it's a ptype of button.

My javascript key handler then does this:

function DoKey(step, dir) {
if (!activeElement.getAttribute('ptype'))
Where is 'activeElement' defined? Usually the element passes a
reference to itself using 'this':

<button onclick="DoKey(this);" ...>
Then assign it to a variable in the function:

function DoKey(el, step, dir) {
if ( !el.getAttribute('ptype') )
//...

numericalField(step, dir);
else switch(activeElement.getAttribute('ptype')) {
case 'numerical':
numericalField(step, dir);
You could ditch ptype and set the function to call directly:

<button onclick="buttonField(this, step, dir);" ...>
Where step and dir have some value you haven't shown.

[...]
I can't help but think that I should be able to do something like this:

(activeElement.getAttribute('ptype')+'Field')(step , dir)

to call the function directly... Is there a construct that works like
that or should I stick with the case construct?


Use the case (or if or whatever) statement on your server and set the
event handler to the appropriate value in the HTML source.
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>
Apr 24 '06 #4
st*****@gmail.com wrote:
In a recent message, someone pointed out that all Javascript functions
are passed through the Window object, so you can do this:


It was wrong then (and I commented on it), and it is still wrong now.

Please learn to quote.
PointedEars
--
Bill Gates isn't the devil -- Satan made sure hell
_worked_ before he opened it to the damned ...
Apr 24 '06 #5

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

Similar topics

3
by: Hal Vaughan | last post by:
I'm not sure what the correct name for this would be. I'd think it's either an indirect reference, or a pointer, or something like that. I'm working on a program that would call a series of...
1
by: suresh | last post by:
Namasivayah, Stroustrup says when indirect array is used for reordering a valarray the index cannot be repeated twice(page 679). But Nicolai Josuttis in his book on C++ standard library, page...
1
by: Sam Phillips | last post by:
Howdy, I'm trying to apply color schemes to forms and subforms. I'm using a global function to change the colors/fonts of controls. Right now it correctly loops over the controls in the main...
13
by: ganeshb | last post by:
Hi, What C statement(s) would translate to indirect jmp in assembly? I know that function pointer invocation would translate to indirect 'call' instruction, but I am not sure what will lead to...
2
by: George Ter-Saakov | last post by:
Hi. I need to use the COM objects indirectly from ASP.NET pages. I.E. ASP.NET calls Managed C++ class which makes the call to DOMDocument ( It has to parse out the XML file). Do i need to do...
8
by: Gaetan | last post by:
Is is possible in C# to have the equivalent of an array of function pointers in C? I have a situation where a top level class exposes methods like Add, Delete, ... and a few child classes with...
2
by: Zioth | last post by:
class A { function Get() {return $this;} } $obj = new A(); In php5, the following statement is valid: $x = $obj->Get()->Get(); In php4, I get the following error:
9
by: BartlebyScrivener | last post by:
I know this must have been answered a hundred times, but I must be searching on the wrong terminology. Let's say I have a module foo.py that imports os. I make another script called bar.py...
5
by: Rahul B | last post by:
Hi, I am having the following issues while trying to restrict the current user from creating any objects. Below is the privileges for the user and response when i try to create a table in that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.