troubleshooting Question

How to combine two onload events?

Avatar of baxtalo
baxtalo asked on
JavaScriptASP
7 Comments1 Solution392 ViewsLast Modified:
I have a dropdown menu which auto populates the next four months. In order to validate the other fields I need to place another OnLoad event in the BODY opening tag.
<body OnLoad="init()">
 When I do this my dropdown won't auto populate anymore.
What can I do in order to be able to use both OnLoad events?
Thank you for your help.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
	var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
function nextThreeMonth(select) {
		var d = new Date();
		for(var i=1;i<=3;i++) {
			var o = document.createElement("option");
			var m = new Date(2000,d.getMonth()+i,1).getMonth();
			o.text = months[m];
			o.value = m+1;
			try { select.add(o,null); } catch(e) { select.add(o); }
		}
	}
	window.onload = function() {
		nextThreeMonth(document.getElementById('s'));
	}
</script>
</head>
<body>
<select id="s"></select>
</body>
</html>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros