0

Javascript code (In another file in the same directory):

function js(str)
{
 alert(str);
}

PHP code(in current file):

<?php
echo '<script  type="text/javascript" src="C:\xampp2\htdocs\ARD\call_jsfunc_diff_page.js">  </script>';
echo '<script>js("hello!!")</script>';
?>

I have checked on many links on the internet, i think i'm doing the right way, but the javascript function js(str) doesn't get called !!

Can somebody help me please ??

2
  • Before you edit the question, you are calling the wrong function and give the relative src than giving the absolute path. Commented Jul 15, 2014 at 10:12
  • First of all, is the path to your external js-file correct? Try adding alert('Hello') at top of that file, so you know it is called. Second: Do you get an error in your console (something like 'call to undefined function js'?). It's possible the function isn't initialized yet at the moment you call it. Try setting a timeout before calling the function. Commented Jul 15, 2014 at 10:18

1 Answer 1

2

Before you edited the question: You called the function js but you are trying to call the func function.

Access to local hard disks is also problematic. Use a relative URI and access the .js over HTTP instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Can you please elaborate?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.