473,881 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a tough question

hi all
what I want to do is as below
start a function
halt on,
until some event occurs(maybe user click)
and then return some value accordingly.
Or is it possible to do this stuff?
Jun 27 '08 #1
16 1363
Mr Shore <sh*********@gm ail.comwrites:
hi all
what I want to do is as below
start a function
halt on,
until some event occurs(maybe user click)
and then return some value accordingly.
Or is it possible to do this stuff?
No, and you don't want to do that anyway. Just do whatever it is you
need to do from the onclick handler. Don't fight the event model.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #2
On Apr 14, 2:07 am, Joost Diepenmaat <jo...@zeekat.n lwrote:
Mr Shore <shore.cl...@gm ail.comwrites:
hi all
what I want to do is as below
start a function
halt on,
until some event occurs(maybe user click)
and then return some value accordingly.
Or is it possible to do this stuff?

No, and you don't want to do that anyway. Just do whatever it is you
need to do from the onclick handler. Don't fight the event model.

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
so what do you think of the prompt function?
Jun 27 '08 #3
Mr Shore <sh*********@gm ail.comwrites:
>No, and you don't want to do that anyway. Just do whatever it is you
need to do from the onclick handler. Don't fight the event model.

so what do you think of the prompt function?
It's a hack; it prevents the user from doing anything else while the
prompt is active, and there is no way to replicate the behaviour with
user-written javascript. The "best" you can do is to disable everything
else on the page (using some kind of overlay, for instance). That
/still/ won't give you the "call function and use return value"
mechanism, and there is no reason you need that - the event model is
much more flexible.

You just need

show_my_prompt( data,function(v alue) {
// do stuff with value
});

instead of

var value = prompt(data);
// do stuff with value.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #4
On Apr 14, 2:37 am, Joost Diepenmaat <jo...@zeekat.n lwrote:
Mr Shore <shore.cl...@gm ail.comwrites:
No, and you don't want to do that anyway. Just do whatever it is you
need to do from the onclick handler. Don't fight the event model.
so what do you think of the prompt function?

It's a hack; it prevents the user from doing anything else while the
prompt is active, and there is no way to replicate the behaviour with
user-written javascript. The "best" you can do is to disable everything
else on the page (using some kind of overlay, for instance). That
/still/ won't give you the "call function and use return value"
mechanism, and there is no reason you need that - the event model is
much more flexible.

You just need

show_my_prompt( data,function(v alue) {
// do stuff with value

});

instead of

var value = prompt(data);
// do stuff with value.

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
ok,seems i have to give up that idea
thanks for the quick reply
Jun 27 '08 #5
On Apr 14, 2:37 am, Joost Diepenmaat <jo...@zeekat.n lwrote:
Mr Shore <shore.cl...@gm ail.comwrites:
No, and you don't want to do that anyway. Just do whatever it is you
need to do from the onclick handler. Don't fight the event model.
so what do you think of the prompt function?

It's a hack; it prevents the user from doing anything else while the
prompt is active, and there is no way to replicate the behaviour with
user-written javascript. The "best" you can do is to disable everything
else on the page (using some kind of overlay, for instance). That
/still/ won't give you the "call function and use return value"
mechanism, and there is no reason you need that - the event model is
much more flexible.

You just need

show_my_prompt( data,function(v alue) {
// do stuff with value

});

instead of

var value = prompt(data);
// do stuff with value.

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
still a question
how to pass variable parameters in js?
function t(a,b){
alert(b);
}

t(b="hi");
which i meant to set second parameter of function t as "hi" but failed
Jun 27 '08 #6
Mr Shore <sh*********@gm ail.comwrites:
still a question
how to pass variable parameters in js?
function t(a,b){
alert(b);
}

t(b="hi");
which i meant to set second parameter of function t as "hi" but failed
Javascript only does positional parameters. Just do

t(undefined,"hi ");

or whatever you want to indicate "this parameter is useless" for the
first parameter. A possible downside to using undefined is that
undefined is a variable, and so can be set to a value that isn't
undefined. Anyone actually setting undefined to some defined value
should of course have their computer taken away.

See also: <http://developer.mozilla.org/en/docs/
Core_JavaScript _1.5_Reference: Functions:argum ents>

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #7
VK
On Apr 13, 11:10 pm, Joost Diepenmaat <jo...@zeekat.n lwrote:
Anyone actually setting undefined to some defined value
should of course have their computer taken away.
Thank you, bro! :-) :-|
Jun 27 '08 #8
On Apr 14, 3:10 am, Joost Diepenmaat <jo...@zeekat.n lwrote:
Mr Shore <shore.cl...@gm ail.comwrites:
still a question
how to pass variable parameters in js?
function t(a,b){
alert(b);
}
t(b="hi");
which i meant to set second parameter of function t as "hi" but failed

Javascript only does positional parameters. Just do

t(undefined,"hi ");

or whatever you want to indicate "this parameter is useless" for the
first parameter. A possible downside to using undefined is that
undefined is a variable, and so can be set to a value that isn't
undefined. Anyone actually setting undefined to some defined value
should of course have their computer taken away.

See also: <http://developer.mozilla.org/en/docs/
Core_JavaScript _1.5_Reference: Functions:argum ents>

--
Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/
thanks a lot
finally i tried your version,
which passed the function string then eval
Jun 27 '08 #9
On Apr 14, 5:42 am, Mr Shore <shore.cl...@gm ail.comwrote:
On Apr 14, 5:32 am, Joost Diepenmaat <jo...@zeekat.n lwrote:
Mr Shore <shore.cl...@gm ail.comwrites:
but I don't know how to pass an executing function directly?
I really hope that one day there will be a seriously good book about
javascript. Anyway:
function call_me_back(fu n) {
var value = 42;
fun(value);
}
call_me_back(fu nction(value) {
alert(value);
});
function cb(v) {
alert("V: "+v);
}
call_me_back(cb );
--
Joost Diepenmaat | blog:http://joost.zeekat.nl/|work:http://zeekat.nl/

got it!
thanks a lot:)
but now i think maybe i'll stick to the error prone though eval
version
because otherwise it'll be quite hard for me to make it work in all
occasions,eg. the variable num of parameters and so on
error prone or general
i choose the later
Jun 27 '08 #10

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

Similar topics

13
2193
by: Elaine | last post by:
This has to do with self-joins and includes a running balance problem. Is it possible to do this using SQL alone? Amortization schedule -------------------------- Givens: beginning balance, payment amount, # of periods, rate per period schedule would consist of columns for balance, principal paid,
9
17835
by: denis | last post by:
Hi there, I got a tough interview questions lately, and I would like to hear your opinion: An array of N chars is given Write an efficient algorithm to find all the repeating substring with a minimal size
3
929
by: denis_browne | last post by:
Hi there, I got a tough interview questions lately, and I would like to hear your opinion: An array of N chars is given Write an efficient algorithm to find all the repeating substring with a minimal size of 2
12
1493
by: Mr Shore | last post by:
how to do the follows in IE: there's page A with element a pop a new page B from script in A and append element a into B after closing page B put element a back into A 'IE' solution only
4
1959
by: Jim Rutledge | last post by:
ok ok , anyone know anything on this tough question? How do you determine the length in seconds that a midi file is , or any audio file for that matter ?
0
9776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10718
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...
0
9554
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7953
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
7110
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
5781
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...
0
5977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4196
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3225
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.