BILL Carlisle
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/bu tton-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/bu tton-r.gif " alt="" /></td>
</tr></table>
Thank you, Bill
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/bu
<td class="t15C"><a href="javascript: unknown syntax ;">Print Labels</a></td>
<td class="t15R"><img src="/i/themes/theme_15/bu
</tr></table>
Thank you, Bill
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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/bu tton-l.gif " alt="" /></td>
<td class="t15C"><a href="javascript:CallVBScr ipt('Btn1_ onclick()' );">Print Labels</a></td>
<td class="t15R"><img src="/i/themes/theme_15/bu tton-r.gif " alt="" /></td>
</tr></table>
</body>
</html>
<!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/bu
<td class="t15C"><a href="javascript:CallVBScr
<td class="t15R"><img src="/i/themes/theme_15/bu
</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/bu tton-l.gif " alt="" /></td>
<td class="t15C"><a href="vbscript:Btn1_onclic k()">Print Labels</a></td>
<td class="t15R"><img src="/i/themes/theme_15/bu tton-r.gif " alt="" /></td>
</tr>
</table>
</body>
</html>
<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/bu
<td class="t15C"><a href="vbscript:Btn1_onclic
<td class="t15R"><img src="/i/themes/theme_15/bu
</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.
Regards,
Rob.
ASKER
That's the one that worked!
Thank you all for your input!
Bill
Thank you all for your input!
Bill
<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>