Link to home
Start Free TrialLog in
Avatar of BILL Carlisle
BILL CarlisleFlag for United States of America

asked on

How do I call a VB button script from my custom javascript button?

How do I call a VB button script from my custom javascript button?

1.) The VB script:
<SCRIPT LANGUAGE=VBScript>
Sub Btn1_onclick()
     MsgBox("Got it!")
End Sub
</SCRIPT>

2.) The normal button call that works
<INPUT TYPE=BUTTON NAME=Btn1 VALUE="Print Labels">

3.) My custom button with the "unknown syntax":
<table class="t15Button" cellspacing="0" cellpadding="0" border="0"  summary=""><tr>
<td class="t15L"><img src="/i/themes/theme_15/button-l.gif" alt="" /></td>
<td class="t15C"><a href="javascript:          unknown syntax           ;">Print Labels</a></td>
<td class="t15R"><img src="/i/themes/theme_15/button-r.gif" alt="" /></td>
</tr></table>

Thank you, Bill
ASKER CERTIFIED SOLUTION
Avatar of Kiran Paul VJ
Kiran Paul VJ
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
how to call vbscript from javascript

<html>
<head>
<title>Untitled</title>
</head>
<body>
<SCRIPT LANGUAGE="VBSCRIPT">
Function returnValue()
returnValue = "Hello, world!"
End Function
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
function getVBValue(){
var vbval = returnValue();
alert("VBScript value = " + vbval);
}
getVBValue();
</SCRIPT>
</body>
</html>
or you can try this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<SCRIPT LANGUAGE=VBScript>
Sub Btn1_onclick()
     MsgBox("Got it!")
End Sub
</SCRIPT>

<script language="javascript">
function CallVBScript(functionName)
{
      eval(functionName);
}
</script>
</head>

<body>
<table class="t15Button" cellspacing="0" cellpadding="0" border="0"  summary=""><tr>
<td class="t15L"><img src="/i/themes/theme_15/button-l.gif" alt="" /></td>
<td class="t15C"><a href="javascript:CallVBScript('Btn1_onclick()');">Print Labels</a></td>
<td class="t15R"><img src="/i/themes/theme_15/button-r.gif" alt="" /></td>
</tr></table>

</body>
</html>
Make it as a function:

<html>
      <head>
            <title>Script Demo</title>
            <script type="text/vbscript">
                  function Btn1_onclick()
                        MsgBox "Got it!"
                  end function

            </script>
      </head>
<body>
      <table class="t15Button" cellspacing="0" cellpadding="0" border="0"  summary="">
            <tr>
                  <td class="t15L"><img src="/i/themes/theme_15/button-l.gif" alt="" /></td>
                  <td class="t15C"><a href="vbscript:Btn1_onclick()">Print Labels</a></td>
                  <td class="t15R"><img src="/i/themes/theme_15/button-r.gif" alt="" /></td>
            </tr>
      </table>


</body>
</html>
I think gops1 has it right there.  The main difference is that you have to use the "vbscript" before the function name, so the code knows which language the function is, that you are calling.  If you specify "javascript", but it is a "vbscript" function, you will get the syntax error.

Regards,

Rob.
Avatar of BILL Carlisle

ASKER

That's the one that worked!

Thank you all for your input!
Bill