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
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply 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: 159
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 opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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: 159
Thanks a lot for the replies,

was thinking about using jQuery and will look into it

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