[Javascript] Javascript include problem?

John Warner john at jwarner.com
Sat Oct 2 10:36:41 CDT 2010


Not sure on PHP (I'm a ASP.NET guy) but it sounds like you are still not
understanding what John was suggesting (note I'm a different John)

Your JavaScript file (.js) will contain only JavaScript, absolutely no
html markup nor should any PHP be present. Of course you can bury anything
in comments. Inside the js file there are no <script> tags all this is
handled elsewhere in the 'process'. For example let's pretend the next few
lines between the words begin and end are the .js file, Note begin and end
are NOT part of the file just provided to make it easier to read:
begin 

function helloJason() {
      alert('Hello Jason!') ;
    }

end

only what is between begin and end is our Jason.js file

In your html

<html>
<head>
<script type="text/javascript" language="javascript"
src="Jason.js"></script>
</head>
<body>
<input type="button" id="hello-world2" value="Hello"
onClick="helloJason();" />
</body>
</html>

Clear as mud right :-)

John Warner


> -----Original Message-----
> From: javascript-bounces at lists.evolt.org [mailto:javascript-
> bounces at lists.evolt.org] On Behalf Of Jason Pruim
> Sent: Saturday, October 02, 2010 10:17 AM
> To: JavaScript List
> Subject: Re: [Javascript] Javascript include problem?
> 
> 
> On Oct 1, 2010, at 10:14 PM, John List wrote:
> 
> > On 10/01/2010 09:47 PM, Jason Pruim wrote:
> >> Hey Everyone,
> >>
> >> I just signed up for the list and I can't wait to get really deep
> >> into javascript and be able to make amazing things happen.
> >>
> >> But right now I'm running into a small problem...
> >>
> >> I have a javascript page that I am including in a combination php/
> >> html page. (Yes I'm going for everything! :)) and the javascript
> >> works just fine if I load the page independently but when I try and
> >> view it via an include it won't display the map...
> >>
> >> Link for the stand alone page:
> HTTP://jason.pruimphotography.com/dev/cms2/includes/google/testmap.html
> >>
> >> Link for included page:
> HTTP://jason.pruimphotography.com/dev/cms2/events/display1.php?id=46
> >>
> >> Any idea what the problem is? :)
> >> Thanks in advance for any help or pointers you can give! :)
> >
> > Jason, it looks like your "javascript page" is a complete html page,
> > not just javascript. You are including that in another html page, so
> > you wind up with multiple <html>, <head>, and <body> tags.
> >
> > Put your javascript only (no html) in its own .js file, and
> > reference that file in a <script src= > tag in the head of the main
> > page. (Or, if you prefer, use php to include it between  <script></
> > script> tags in the head of the page.)
> >
> > Hope that helps,
> >
> > John
> 
> Hi John,
> 
> I did as you suggested, split off just the javascript into it's
> own .js file and tried including it both ways (IE: <script
> src="blahblahblah"></script > and a php include)
> 
> Neither worked... had the same result... I'm wondering if something
> with the include is messing it up? Should I just try and put the whole
> thing in a <script> </script> in the head of the file? Not the most
> portable but if it would work...
> 
> THanks again for your help John!
> 
> 
> >
> >
> > _______________________________________________
> > Javascript mailing list
> > Javascript at lists.evolt.org
> > http://lists.evolt.org/mailman/listinfo/javascript
> 
> _______________________________________________
> Javascript mailing list
> Javascript at lists.evolt.org
> http://lists.evolt.org/mailman/listinfo/javascript




More information about the Javascript mailing list