WebmasterSite.net

Onload events

Version: 5.1.44
URL:

PrintPrint


Onload events
jayweb
Forum Regular

Usergroup: Customer
Joined: Nov 27, 2006

Total Topics: 131
Total Posts: 384
quote post #1
Posted 09/01/10 - 1: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?


jayweb
Forum Regular

Usergroup: Customer
Joined: Nov 27, 2006

Total Topics: 131
Total Posts: 384
quote post #2
Posted 09/01/10 - 2: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
Avatar

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

Total Topics: 65
Total Posts: 7614
quote post #3
Posted 09/01/10 - 10: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.

Edited by Paul on 09/01/10 - 10:06 PM
jayweb
Forum Regular

Usergroup: Customer
Joined: Nov 27, 2006

Total Topics: 131
Total Posts: 384
quote post #4
Posted 09/02/10 - 3:26 AM:

Brilliant, thanks Paul.
 
Search thread for
Download thread as


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