Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2009
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If function works display text

    I have a simple function to test active x :

    Code:
    <script language="javascript">
    function activex() //start excel invisible just to test active x object
    {
    var excApp = new ActiveXObject("Excel.Application");
    excApp.visible = false;
    excApp.Quit();
    }
    </script>
    button to execute function in html:

    Code:
    <button type="button" onClick="activex()">Test ActiveX</button>
    this works fine, im looking to have when users click this button..It runs the fuction, if the function is successful it returns some text like "success"next to the button, if the function fails it returns text "fail" or somethig like that.

    can someone help ?
    thank you

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Naturally this will only work in an IE browser:-

    Code:
    <script type = "text/javascript">
    
    function activex() {  //start excel invisible just to test active x object
    document.getElementById("mymessage").innerHTML = "";
    var excApp = new ActiveXObject("Excel.Application");
    if (excApp == "Microsoft Excel") {
    document.getElementById("mymessage").innerHTML = "Success";
    excApp.visible = false;
    excApp.Quit();
    }
    else {
    document.getElementById("mymessage").innerHTML = "Failed";
    }
    }
    </script>
    
    <button type="button" onClick="activex()">Test ActiveX</button>&nbsp &nbsp<span id = "mymessage"></span>

    Another test which displays a message in non-IE browsers:-

    Code:
    <script type = "text/javascript">
    
    if (window.ActiveXObject) {
    try {
    var excelApp = new ActiveXObject ("Excel.Application");
    if (excelApp == "Microsoft Excel") {
    alert ("Excel OK");  // or show message in a <span>
    }
    excelApp.Visible = false;
    excelApp.Quit();
    }
    catch (err) {
    var txt="There was an error on this page. "
    alert(txt + err.message);
    }
    }
    else {
    alert ("Your browser does not support Active-X.");
    }
    </script>
    Quizmaster: In mythology, what term for a potion that increases sexual desire is derived from the name of the Greek goddess of love?
    Contestant: Viagra
    Last edited by Philip M; 07-18-2012 at 06:01 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New Coder
    Join Date
    Apr 2009
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    perfect. thank you very much


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •