Reputation: 2146
I am calling the javascript function from another file in href, I want to know if there is any way to call it in php without using href?
call from href
<script language="javascript" type="text/javascript" src="js/myjs.js"></script>
<a href="javascript:NewCal()">Link1</a>
how can I use "javascript:NewCal()" in PHP echo?
Upvotes: 2
Views: 1652
Reputation: 112
yes you can cal function like:
<a href = "#"> <spam name="spmNewCal" onclick="javascript:NewCal()" id="spmNewCal" /></a>
Upvotes: -1
Reputation: 64526
PHP can't directly call a Javascript function because PHP runs on the server side and Javascript on the client.
What you can do is echo the Javascript call into an onclick
handler or any other event handler for example:
<?php
echo '<a href="javascript:NewCal()">Link1</a>';
echo '<p onclick="NewCal()">Click me</p>';
?>
If you want to execute it on load:
echo '<script>window.onload = function(){ NewCal(); };</script>';
Upvotes: 1
Reputation: 2904
Try this code
echo "<a href=\"javascript:NewCal();\">";
Upvotes: 0