File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes JavaScript page load get value of anchor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JavaScript page load get value of anchor" Watch "JavaScript page load get value of anchor" New topic
Author

JavaScript page load get value of anchor

Niall Loughnane
Ranch Hand

Joined: Dec 07, 2006
Posts: 208
Hi,

I have the following HTML and JavaScript code:



what i am trying to do is to alert the value of the field "anchor" when the page loads,

currently it only alerts when the field is clicked,

is it possible to alert when the page loads?

Thanks in Advance,

Niall
Jee Ba
Greenhorn

Joined: Feb 08, 2011
Posts: 7
Yes it is possible,


But if you want something more CrossBrowser, maybe you should check the jquery library ready event
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60791
    
  65

Jee Ba wrote:Yes it is possible,


Bad practice! Behavior shouldn't be mixed in with the document markup.

The original tactic of using:was on the right track, but should be:
Note, no parens!


But I do agree that using jQuery for event handling is great idea.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jee Ba
Greenhorn

Joined: Feb 08, 2011
Posts: 7
I agree with Mr Bear, its a bad practice to put javascript on your HTML. Using external js files, will make your code more easy to read , also know as "beautiful code". Hope this complement your original question.
Niall Loughnane
Ranch Hand

Joined: Dec 07, 2006
Posts: 208
Thanks a lot for the replies,

was thinking about using jQuery and will look into it

Thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JavaScript page load get value of anchor
 
Similar Threads
not able to redirect to html file from a jsp
How to get window.location.hash to work in Fire Fox?
how to let javascript function recgonize java bean?
Cannot see the JavaScript code I wrote when I hit script tab on firebug :(
anchor tag and window.event.srcElement dont work