...">

How to call javascript function from vbscript

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 shows that the type does not match how to achieve it. please help me.

Thanks Mihir

+3
source share
4 answers

Try it...

<%@ Language=VBScript %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<script language="JavaScript" >
function jsfunction()
{
  alert("Hello")
}

</script>
<%
Response.Write "Calling =" jsfunction() "."
%>
</BODY>
</HTML>
+2
source

Assuming you need this client side, not ASP;

If you place a JScript block in front of the VBScript block (or make a call to the load event), that will work fine. (IE only)

...
<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()">
...
+8
source

VBScript Javascript VBScript:

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

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>    

: Javascript VBScript

Function myVBFunction()
  myJavascriptFunction()  
End Function
+3

return, , , response.write -

-

<%@ Language=VBScript %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<script language="JavaScript" runat="server">
function test() {
return "Test";
}
</script>
<%
Response.Write "Value returned =" & test() & "."
%>
</BODY>
</HTML>
+1

All Articles