Thread: onclick event
View Single Post
  #2 (permalink)  
Old April 11th, 2004, 03:10 PM
planoie's Avatar
planoie planoie is offline
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

Have you tried it?

Yes, you can. You could write a whole javascript program in a control's event handler attribute, assuming you can do so without needing to use the quote character that the attribute's value is enclosed in. You just need to separate the lines by a semi-colon:

<input type="button" onClick="alert('once');alert('twice');alert('three times a button');">

I've found you don't need to have the "javascript:" prefix in a handler attribute, but it's helpful when you use it in an <a> tag:

<a href="javascript:alert('hello');">click me</a>

You can pass anything you want to a javascript function. Any valid code including variables HTML controls, constants, strings, etc.

Remember that ASP is server side. Once you are in the context of running javascript you are in the browser so you can't run ASP code. You have to make a page request (post or get) for that.

Work smarter, not harder
Reply With Quote