p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript (http://p2p.wrox.com/forumdisplay.php?f=85)
-   -   onclick event (http://p2p.wrox.com/showthread.php?t=11686)

pigtail April 10th, 2004 11:46 PM

onclick event
When I use onclick to execute a javascript:myfunctionname(), can I have more statements separated by a semi-colon after the colon or am I limited to only one statement after the colon?

If I want to pass an array, can I insert the array name between the ()? Sorry, I have asked this question in another entry. I didn't think of this possibility until now.

If I want to execute an ASP for my onclick and pass a string like "abc, efgh, ijklm", do I need a single quote around my values? What is the proper syntax?

planoie April 11th, 2004 03:10 PM

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

All times are GMT -4. The time now is 12:01 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.