Webmastersite.net
Register Log In

Onload events

Comments on Onload events

webflair
Forum Regular

Usergroup: Customer
Joined: Nov 27, 2006

Total Topics: 187
Total Comments: 465
Posted Sep 01, 2010 - 2:41 PM:

Hi

I am trying to add an onload event, but there is aready an onload in the code when the page loads, so my onload doesn't work.

Here's what I need to do...

I am trying to automatically set the date in some drop down form fields.

I wanted to add the following code to the opening body tag.. onload=setDrops(document.searchform)

and the following code to the head section...

<SCRIPT language=JavaScript>
<!--
var now = new Date();
var theday = now.getDate()-1;
var themonth = now.getMonth();
var theyear = now.getFullYear();

function setDrops(theForm) {
theForm.day.selectedIndex = theday;
theForm.month.selectedIndex = themonth;

var found = 0;
for(i=1;i<theForm.year.options.length;i++) {
if (theForm.year.options[i].value == theyear) {
found = i;
break;
}
}
theForm.year.selectedIndex = found;
}
//-->
</SCRIPT>

However, because WSN links already inserts an onload event, it doesn't work. How can I use my onload event with WSN links?


webflair
Forum Regular

Usergroup: Customer
Joined: Nov 27, 2006

Total Topics: 187
Total Comments: 465
Posted Sep 01, 2010 - 3:29 PM:

I have now tried using this...

<script type="text/javascript>
setDrops(document.searchform);
</script>

at the bottom of the page, and it works in all browsers but Chrome, is there a solution that will work with all browsers?
Paul
developer

Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California

Total Topics: 61
Total Comments: 7868
Paul
Posted Sep 01, 2010 - 11:03 PM:

onload is essentially equivalent to jquery's document ready function, so put setDrops(document.searchform); in jquery/documentready.txt. That's the file (empty by default) to place any additional content that should be inserted to run when the page has fully loaded.
webflair
Forum Regular

Usergroup: Customer
Joined: Nov 27, 2006

Total Topics: 187
Total Comments: 465
Posted Sep 02, 2010 - 4:26 AM:

Brilliant, thanks Paul.
Search thread for
Download thread as
  • 0/5
  • 1
  • 2
  • 3
  • 4
  • 5



Sorry, you don't have permission to post posts. Log in, or register if you haven't yet.