4

how to call javascript function from vbscript. i wrote like this

<script type="text/vbscript">
jsfunction()
</script>
<script type="text/javascript">
function jsfunction()
{
 alert("Hello")
}
</script>

but it is showing that type mis match how to achieve it. please help me.

Thank you, Mihir

asked May 23, 2011 at 9:48
0

4 Answers 4

9

Assuming you want this client side as opposed to ASP;

If you place the JScript block before the VBScript block (or wire the call to a load event) that will work fine. (IE only of course)

...
<head>
<script type="text/vbscript">
 function foo
 call jsfunction()
 end function
</script>
<script type="text/javascript">
 function jsfunction()
 {
 alert("hello");
 }
</script>
</head>
<body onload="foo()">
...
Charlie
24k12 gold badges64 silver badges96 bronze badges
answered May 23, 2011 at 10:02

Comments

4

Calling a VBScript function from Javascript Your VBScript:

Function myVBFunction()
 ' here comes your vbscript code
End Function

Your Javascript:

function myJavascriptFunction(){
 myVBFunction(); // calls the vbs function
}
window.onload = myJavascriptFunction;
Alternatives (incompatible in some IE versions):
 // This one:
window.onload = function(){ myVBFunction(); }
 // This will also work:
window.onload = myVBFunction();
 // Or simply:
myVBFunction(); 
 // From a hardcoded link, don't write a semicolon a the end:
<a href="#" onclick="VBscript:myVBFunction('parameter')">link</a> 

Inversed: Calling a Javascript function from VBScript

Function myVBFunction()
 myJavascriptFunction() 
End Function
GAThrawn
2802 silver badges13 bronze badges
answered Aug 27, 2012 at 16:14

Comments

3

Try this ...

<%@ Language=VBScript %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<script language="JavaScript" >
function jsfunction()
{
 alert("Hello")
}
</script>
<%
Response.Write "Calling =" jsfunction() "."
%>
</BODY>
</HTML>
answered May 23, 2011 at 9:55

1 Comment

@road.. thank you but can you explain Response.Write "Calling =" jsfunction() "." why you wrote like this... please
1

Instead of alert we should write return which is in turn print the values on page using response.write-

code is below -

<%@ Language=VBScript %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<script language="JavaScript" runat="server">
function test() {
return "Test";
}
</script>
<%
Response.Write "Value returned =" & test() & "."
%>
</BODY>
</HTML>
answered Feb 1, 2014 at 16:19

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.