how do i run javascript?

T

themasterrocker

Guest
basically the title says it.
I need to run this file called songscript.js and i cant remember the code i know its something like <body_onload> im not sure if it's meant to be <body_onload="songscript" for it? It's in my root directory and just needs to run when the page has loaded.
 

phpasks

New Member
Messages
145
Reaction score
0
Points
0
basically the title says it.
I need to run this file called songscript.js and i cant remember the code i know its something like <body_onload> im not sure if it's meant to be <body_onload="songscript" for it? It's in my root directory and just needs to run when the page has loaded.

Code:
/** script.js *///

function call()
{
    alert("Call On Load Page");
}
HTML:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="script.js"></script>
</head>
<body onload="call()">
Just Call
</body>
</html>
 
T

themasterrocker

Guest
Wiowky gave it me but he's not responding to messages and hasn't been on msn and i don't know what it was but its not like this one but ill give it a try.

Code:
/** script.js *///

function call()
{
    alert("Call On Load Page");
}
HTML:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="script.js"></script>
</head>
<body onload="call()">
Just Call
</body>
</html>

Yeah i used your code but i don't know where you want me to put this :
Code:
/** script.js *///

function call()
{
    alert("Call On Load Page");
}
 
Last edited by a moderator:

phpasks

New Member
Messages
145
Reaction score
0
Points
0
Wiowky gave it me but he's not responding to messages and hasn't been on msn and i don't know what it was but its not like this one but ill give it a try.



Yeah i used your code but i don't know where you want me to put this :
Code:
/** script.js *///

function call()
{
    alert("Call On Load Page");
}

script.js save page in your folder where is store that html page.

Then run & see it.


Otherwise you will send your demo page link & i try it.
 

LHVWB

New Member
Messages
1,308
Reaction score
0
Points
0
Basically you just need to put the below html tag within your "<head></head>" tags, it will include the .js file and allow you to access the code in it. You should change the src based on the location of the .js file in relative to the html document that you are accessing it with.

HTML:
<script language="javascript" src="songscript.js"></script>

Then change your <body> tag so that it has the onload element, like the example below. You will however have to work out which javascript function you need to call, you can work this out by having a look at the code within the songscript.js file.

HTML:
<body onload="javascript:function_to_call()">
 
Last edited:
T

themasterrocker

Guest
This feature doesn't work right. (I use firefox with the addon of firebug) and it's errored becaue it doesn't know what the function is to call
HTML:
<body onload="javascript:function_to_call()">

Edit:I AM NOW GIVING 50 CREDITS FOR THE FIRST ONE TO GET HELP ME AND GET MY SITE'S JAVASCRIPT WORKING
 
Last edited by a moderator:

LHVWB

New Member
Messages
1,308
Reaction score
0
Points
0
Sorry I made a mistake with my post, you need to put the below html code within the <head></head> tags not the <header></header> tags.

HTML:
<script language="javascript" src="songscript.js"></script>
 
Last edited:
T

themasterrocker

Guest
erm. i guess so. but also I've been doing something else and when my body loads its gotta load another file. will this stop the javascript from running?? and heres the code

Code:
var http = getHttpObj();
var checked = 0;

function getHttpObj() {
	if (XMLHttpRequest) {
		return new XMLHttpRequest();
	}
	else {
		var axList = new Array('Msxml2.XMLHttp.5.0', 'Msxml2.XMLHttp.4.0', 'Msxml2.XMLHttp.3.0', 'Msxml2.XMLHttp', 'Microsoft.XMLHttp');
		var axObj;
		
		for (var i = 0; i < axList.length; i++) {
			try {
				axObj = new ActiveXObject(axList[i]);
				return axObj;
			}
			catch (e) {
				continue;
			}
		}
	}
	return false;
}

function switchSong() {
	http.open('GET', 'time_remaining.php?show=true', true);
	http.onreadystatechange = readResponse;
	http.send(null);
}

function readResponse() {
	if ((http.readyState == 4) && (http.status == 200)) {
		var time = parseInt(http.responseText);
		if (time > 0) {
			setTimeout('switchSong()', time + 2 * 1000);
			checked = 0;
		}
		else if (checked < 3) {
			setTimeout('switchSong()', 3 * 1000);
			checked++;
		}
		else {
			setTimeout('switchSong()', 600 * 1000);
		}
		var d = new Date();
		var obj = document.getElementById('songimg');
		obj.src = 'current_song.php?t=' + Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds());
	}
}
 

garrettroyce

Community Support
Community Support
Messages
5,611
Reaction score
249
Points
63
I'm not 100% familiar with java, but, when you use:

<script language="javascript" src="songscript.js"></script>

in the <head> section, you tell the client computer to load the javascript file. Then, you need to tell it when to use the functions within, like when a user clicks a button or link, or opens the page:

<body onload="javascript:function_to_call()">

You probably need some documentation for the script to know how to use it exactly.
 

ASPX.King

New Member
Messages
155
Reaction score
0
Points
0
this script won't just do something automatically, it needs you to code a big gui for it. in other words, it's not right for someone with your level of knowledge.
 
T

themasterrocker

Guest
Yeah, i didn't write it, one of my friends did, i need it to boot onload so its something like although i know its not and my friend is a HTML wizz and checked it about 4 times over. (he got it working on my old website which I deleted)

Code:
<body_onload="songswitch"
 
Last edited by a moderator:

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
there is no "_" it is just a space.

Code:
<body onload="sonswitch()">
 
T

themasterrocker

Guest
It hasn't worked im afraid people. I've tried with the Script to include it on the HTML and not on it. and ive done the code Leaftpiggy gave but it's not worked. It's coming back as an error on Firebug in firefox
 

stamaria

New Member
Messages
5
Reaction score
0
Points
0
Should be enough to put next code just after body tag.
HTML:
<script type="text/javascript" src="songscript.js" />

To work properly, you need to have current_song.php file located on the same directory you have songscript.js and check your php settings are the ones you need to allow that php script work properly.
 
Last edited:
T

themasterrocker

Guest
They have been in same directory for a while, but that code just countered my page completely out. its only loading the background
 
Last edited by a moderator:
Top