I'm trying to learn Javascript. Honestly, I don't know how you guys do it. Anyway, I wanted a little alert box to open when the url is loaded. So I tried a few permutations:
<script type="text/javscript">
window.onload=init;
function init(){
alert ("This boy is working");
document.Haskins.sku.focus();
}
</script>
or
<script type="text/javscript">
window.onload=function (){
alert ("This boy is working");
document.Haskins.sku.focus();
}
</script>
When I type document.Haskins.sku.focus() into the firebug console, it works, so I'm really at a loss here. If you have any suggestions, I'd appreciate it
p.s. I have onload="" in my body tag. I'm trying to migrate to a better implementation
Without your full HTML it's hard to tell what the exact error is, so I will give you a few of my best guesses.
For my first guess, your P.S. is what may hold the key
Your body tag's onload is probably overwriting your script tag's window.onload event.
My next guess is that the DOM may not be ready by the time you try to focus. In other words, your document.Haskins.sku doesn't exist yet when you try to focus() on it.
If this doesn't solve it, see if you can post your complete page including your HTML.
This message board is like MrExcel, so I hope I'm doing the right thing with the code tag. I thought about the prior two suggestions. I put my script all the way at the bottom of the screen, after the formation of the form so that it would exist when it runs. I also deleted the onload="" portion of the body tag to see if that was the reason, and it didn't seem to be. Well, anyway, here's the entire code. It's obvious a lot of clean up work is necessary
Well, after beating my head against the wall for five days and reading books everywhere, I've figured out how to make an html page locally to test code in stead of uploading all the time. I've tried firebug, which is quite handy. I've even reduced it to the smallest item possible, but still can't seem to get it to work.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0074)http://www.scrapbookingsuppliesrus.com/?admin=catalog&layer=feature_update -->
<HTML><HEAD><TITLE>Administration - Catalog</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1"><LINK
</HEAD>
<BODY >
<FORM name=Haskins
action=http://www.scrapbookingsuppliesrus.com/?admin=catalog&layer=feature_update
method=post><SPAN id=test>sku: </SPAN><INPUT maxLength=40 size=10
name=sku><BR><INPUT type=submit value=Submit name=send> <INPUT type=submit value="Clear list" name=clear> </FORM>
<SCRIPT type=text/javscript>
window.onload=function(){
alert ("This boy is working");
document.Haskins.sku.focus();
}
</SCRIPT>
</BODY></HTML>
But then, just as I was about to hit the submit reply button, I figured it out. As you can see from my earlier posts, I misspelled javascript in the tag. I can't believe it...
Bookmarks