Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript not executing on window load 1

Status
Not open for further replies.

jwhite68

IS-IT--Management
Jun 14, 2007
77
BG
When the window loads, it is supposed to execute a piece of Javascript, which highlights a button, and displays links below it.

Here is the code segment for the window load.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>homepage</TITLE>
<link href="main.css" rel="stylesheet" type="text/css">
<link href="ddmenu.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="js/services.js"></script>
<script type="text/javascript">
	window.onload = function () { requestProd(); }
	window.onload = function () { setTimeout('clearPreloadPage()',0); }
</script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
	function clearPreloadPage() 
	{ //DOM
		if (document.getElementById)
		{
			document.getElementById('prepage').style.visibility='hidden';
			document.getElementById('servcountry').style.visibility='visible';
		}
		else
		{
			if (document.layers)
			{ //NS4
				document.prepage.visibility = 'hidden';
				document.servcountry.visibility = 'visible';
			}
			else 
			{ //IE4
				document.all.prepage.style.visibility = 'hidden';
				document.all.servcountry.style.visibility = 'visible';
			}
		}
	}
// End -->
</SCRIPT>

So it is supposed to execute requestProd().

RequestProd() is defined in a file called service.js as:

Code:
function requestProd() {
	document.imgProd.src = 'elements/products1.gif';
	document.imgServ.src = 'elements/services0.gif';
	document.imgEven.src = 'elements/events0.gif';
	document.forms['prods'].find.value = 'products';
	if (!oIFrame) {
		createIFrame();
		setTimeout(requestLinks, 10);
		return;
	}
	var sCountry = document.getElementById("servcountry").value;
	var sServ = document.getElementById("find").value;
	oIFrame.location = "requestlinks.php?find=" + sServ + "&country=" + sCountry;
}

Here are 3 buttons, one of which (the one for Products), should get automatically invoked by the window load:

Code:
<td><a href="#srv"><img src="elements/services0.gif" border="0" name="imgServ" id="imgServ" onclick="requestServ()" /></a></td>
						<td><a href="#srv"><img src="elements/events0.gif" border="0" name="imgEven" id="imgEven" onclick="requestEven()" /></a></td>
						<td><a href="#srv"><img src="elements/products1.gif" border="0" name="imgProd" id="imgProd" onclick="requestProd()" /></a></td>
						<td>

Can anyone think of a reason why the execution of the window load for requestProd() doesnt work?
 
You can only call one .onload per page. You will have to mix these two statements into one.
Code:
window.onload = function() {requestProd(); clearPreloadPage(); }


[monkey][snake] <.
 
Great. Many thanks monksnake. That fixed it. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top