Log in

View Full Version : javascript command help



llorax
04-27-2007, 06:57 PM
is there a javascript command that is the same as <?php include (page); ?>? I'm writing a page using javascript and the page is getting too long. I'd like to have it pull in other sources.


Also my site is built like so:


function projects() {
document.getElementById("content").innerJS = "<h1>Past Projects</h1><br><h2>yesterday's work...</h2>
<script type="text/javascript">

//Define your own array to hold the photo album images
//Syntax: ["path_to_thumbnail", "opt_image_title", "opt_destinationurl", "opt_linktarget"]

var myvacation=new Array()
myvacation[0]=["../photo1.jpg", "", "photo1-large.jpg"]
myvacation[1]=["photo2.jpg", "Our car", ""]
myvacation[2]=["photo3.jpg", "Our dog", "photo3-large.jpg"]
myvacation[3]=["photo4.jpg", "Our hotel", "http://www.gohawaii.com/"]

//initiate a photo gallery
//Syntax: new photogallery(imagearray, cols, rows, tablewidth, tableheight, opt_[paginatetext_prefix, paginatetext_linkprefix])
var thepics=new photogallery(myvacation, 3, 1, '700px', '600px') </script>";
}
function contact() {
document.getElementById("content").innerHTML = "<h1>Contact</h1><br><h2>my 411...</h2>";
}
</script>

When I put javascript inside the element it destroys the rest of the code. How can I fix that?

boogyman
04-27-2007, 08:23 PM
you can link a js file into a html page, however I do not think that there is a method that does the equivalent of a PHP include/require.

you could seperate the code into a seperate function, then when you wanted to call it, just initiate the function

Bob90
04-27-2007, 09:53 PM
To include Javascipt files use

<Script src="(js_file)" type="text/javascript" language="javascript"></script>

just write pure javascript in these files.

As for you code, it needs to be cleaned up a little.

:)

jscheuer1
04-27-2007, 10:29 PM
To include Javascipt files use

<Script src="(js_file)" type="text/javascript" language="javascript"></script>

just write pure javascript in these files.

The current standard is:


<script src="filename.js" type="text/javascript"></script>

Language has been deprecated and will not validate.