...

View Full Version : If function works display text



vsantoro
07-18-2012, 06:02 PM
I have a simple function to test active x :



<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:



<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

Philip M
07-18-2012, 06:30 PM
Naturally this will only work in an IE browser:-


<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:-


<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

vsantoro
07-18-2012, 07:24 PM
perfect. thank you very much



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum