Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 12:18 PM
Kim Forbes
Guest
 
Posts: n/a
Default Calling a Javascript function from a message box

Hello all,

I have simple function that I call from an alert box

alert(testScore);

It works fine. Unfortunately, I do not like the sound and Exclamation
point icon that appears. I'd like a nice message box like VBA message
box #64 to appear. I know hardly anything at all about VB or VBA.
But, I do know you can call a VB function from Javascript. How? Is it
possible to get my testScores to appear from the VB function? Is it
hard? Where do I start looking?

Thanks
Kim
  #2  
Old July 20th, 2005, 12:18 PM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a
Default Re: Calling a Javascript function from a message box

kim.forbes@tch.harvard.edu (Kim Forbes) writes:
[color=blue]
> I have simple function that I call from an alert box[/color]
[color=blue]
> alert(testScore);[/color]
[color=blue]
> It works fine. Unfortunately, I do not like the sound and Exclamation
> point icon that appears.[/color]

There is no sound or exclamation point in my browser.
[color=blue]
> I'd like a nice message box like VBA message
> box #64 to appear. I know hardly anything at all about VB or VBA.[/color]

Me neither, so I don't know what a message box #64 is.
[color=blue]
> But, I do know you can call a VB function from Javascript.[/color]

Not in my browser. I.e., not in general. The specific case where it
works is Internet Explorer on Windows. You are not running Javascript,
but JScript, which has access to the Windows Scripting Host, just like
VBA.
[color=blue]
> How? Is it possible to get my testScores to appear from the VB
> function? Is it hard? Where do I start looking?[/color]

Since it is Microsoft IE only, a good guess would be Microsoft's
webpage, searching for JScript and WSH.

This script will use the WSH function, but will require the user to
allow the ActiveXObject creation (at least in my security setting) .
---
<script type="text/javascript">
function myAlert(str) {
if (window && window.WScript) {
var shell=new ActiveXObject('WScript.Shell');
shell.Popup(str,undefined,undefined,64); // that's the #64?
} else {
alert(str);
}
}
---

You could also make a VBScript function and call it from JScript:
---
<script type="text/vbscript">
Function VBMsgBox(txt)
MyMsgBox = MsgBox(txt,64)
End Function
</script>
<script type="text/javascript">
function myAlert (str) {
if (typeof VBMsgBox != "undefined") {VBMsgBox(str);}
else {alert(str);}
}
</script>
---

In both cases, you must fall back on "alert" for all other browsers and
platforms.

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
  #3  
Old July 20th, 2005, 12:18 PM
steve stevo
Guest
 
Posts: n/a
Default Re: Calling a Javascript function from a message box

you can call a vbscript function from javascript but in my
experience you will have to write the vbscript function first.

<script language="vbscript">
function alert(x)
messagebox(x)
End
</script>

<script language="javascript">
messagebox("blah")
</script>

be aware though that not all browsers will support vbscript
I may be wrong but I think it will only be ie4 +

Hope this helps

Simon Christie

"Kim Forbes" <kim.forbes@tch.harvard.edu> wrote in message
news:de27664f.0310221028.68841754@posting.google.c om...[color=blue]
> Hello all,
>
> I have simple function that I call from an alert box
>
> alert(testScore);
>
> It works fine. Unfortunately, I do not like the sound and Exclamation
> point icon that appears. I'd like a nice message box like VBA message
> box #64 to appear. I know hardly anything at all about VB or VBA.
> But, I do know you can call a VB function from Javascript. How? Is it
> possible to get my testScores to appear from the VB function? Is it
> hard? Where do I start looking?
>
> Thanks
> Kim[/color]


  #4  
Old July 20th, 2005, 12:18 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default Re: Calling a Javascript function from a message box

Kim Forbes wrote:
[color=blue]
> I have simple function that I call from an alert box
>
> alert(testScore);
>
> It works fine.[/color]

Forgive me but I do not see any function here [except of alert(...)].
[color=blue]
> Unfortunately, I do not like the sound and Exclamation
> point icon that appears. I'd like a nice message box like VBA message
> box #64 to appear.[/color]

How does that box look like?
[color=blue]
> I know hardly anything at all about VB or VBA.[/color]

Not a very promising start.
[color=blue]
> But, I do know you can call a VB function from Javascript.[/color]

In Internet Explorer, it is possible to call
a VBScript subroutine from JavaScript.
[color=blue]
> How?[/color]

<script type="text/vbscript" language="VBScript">
<!--
Sub foobar
MsgBox "Hello, world!"
End Sub
'-->
</script>

<script type="text/javascript" language="JavaScript">
<!--
foobar();
//-->
</script>
[color=blue]
> Is it possible to get my testScores to appear from the VB function?[/color]

<computer> Please restate your request. </computer>
[color=blue]
> Is it hard? Where do I start looking?[/color]

A manual of your choice, possibly <http://msdn.microsoft.com/library/>,
or a group of the microsoft.* hierarchy. VB(Script)/VBA is off-topic here.


PointedEars

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles