Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 10th, 2004, 11:46 PM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to pigtail Send a message via Yahoo to pigtail
Default 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?

  #2 (permalink)  
Old April 11th, 2004, 03:10 PM
planoie's Avatar
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
Default

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.

Peter
-------------------------
Work smarter, not harder


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid onclick event? hany ASP.NET 1.0 and 1.1 Professional 7 January 1st, 2006 05:21 AM
onclick event bjackman Access 6 July 15th, 2004 06:54 AM
onClick Event mateenmohd Javascript 4 December 16th, 2003 01:08 AM
onClick event problem mateenmohd Javascript 8 August 2nd, 2003 05:16 AM





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