Calling a Javascript function from a message box

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kim Forbes

    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
  • Lasse Reichstein Nielsen

    #2
    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,unde fined,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/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • steve stevo

      #3
      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="vbscr ipt">
      function alert(x)
      messagebox(x)
      End
      </script>

      <script language="javas cript">
      messagebox("bla h")
      </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.0 310221028.68841 754@posting.goo gle.com...[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]


      Comment

      • Thomas 'PointedEars' Lahn

        #4
        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="VBScr ipt">
        <!--
        Sub foobar
        MsgBox "Hello, world!"
        End Sub
        '-->
        </script>

        <script type="text/javascript" language="JavaS cript">
        <!--
        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

        Comment

        Working...