We help IT Professionals succeed at work.

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

BILL Carlisle
on
267 Views
Last Modified: 2008-01-09
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
Comment
Watch Question

Computer Engineer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Kiran Paul VJComputer Engineer
CERTIFIED EXPERT

Commented:
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>
Kiran Paul VJComputer Engineer
CERTIFIED EXPERT

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

Commented:
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>
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
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.
BILL CarlisleAPEX Developer

Author

Commented:
That's the one that worked!

Thank you all for your input!
Bill

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.