• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaScript page load get value of anchor

 
Niall Loughnane
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65124
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jee Ba
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the replies,

was thinking about using jQuery and will look into it

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic