|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
onClick="javascript: function('value');" or onClick="function('value');"?
What is the best way to do this sort of thing.
onClick="javascript: function('value');" onClick="function('value');" onClick="return function('value');" onClick="javascript: function('value')" onClick="function('value')" onClick="return function('value')" Is there a way you are "suppose" to do it? |
|
#2
|
|||
|
|||
|
no inline javascript statement.
no ; as there is only the option for one statement the most common textbook answer would be onclick="functionName('value')" |
|
#3
|
||||
|
||||
|
Quote:
|
|
#4
|
|||
|
|||
|
Ok,
thanks for clearing that up for me. I'll be using and converting to: onClick="function('value');" Not to sure about this return true or false business though. As some functions of mine don't need to return a value, as they invoke other functions. edit: Also I was just using onClick() event as an example, as in I mean it for all events, onBlur(), onMouseOver(), onMouseDown(), etc. I think that for some of these events, should require a return true; or something. Last edited by Nigorr; 11-21-2002 at 10:41 PM. |
|
#5
|
|||
|
|||
|
I believe that putting javascript inline has been depreciated by W3C.
|
|
#6
|
||||
|
||||
|
You should not use the javascript bit generally, instead you should specify the default script type with a declaration in the head:
Code:
<meta http-equiv="Content-Script-Type" content="text/javascript">
__________________
http://www.rickbull.co.uk/ Help get full alpha-transparency in Internet Explorer - probably won't help, but worth a try
|
|
#7
|
||||
|
||||
|
Quote:
Quote:
<a href="javascript:window.open()">Open Sesame</a> And that construction was never really valid, though it used to work (and it doesn't work anymore). And you will not find your construction in any HTML or JavaScript specification. Quote:
If you want to use two different scripting languages with you event handlers then: <a href="http://www.w3.org/TR/REC-html32">3.2</a> <script type="text/javascript"> document.links[document.links.length-1].onclcick = function() {alert('3.2'); return false} </script> <a href="http://www.w3.org/TR/html4/">4.01</a> <script type="text/perlscript"> ... </script> See Section 18.2.2, Specifying the scripting language, of the HTML 4.01 Specification ( http://www.w3.org/TR/html4/interact/....html#h-18.2.2 ) for the valid ways of specifying your scripting language. That's the actual HTML rules and not something that somebody just made up. Last edited by Charles; 11-22-2002 at 06:37 AM. |
|
#8
|
||||
|
||||
|
So, if I understand your post corrrectly, the psuedo-JavaScript construction onClick="javascript:alert('foo')" is something that you just made up. Yes, as I pointed out some browsers understand what it is that you are trying to communicate to them but that's no reason to go about encouraging others to use your new method when perfectly good and valid methods already exist. There are hundreds of browsers out there, Have you tested your own special method on all of them?
|
|
#9
|
||||
|
||||
|
Quote:
Quote:
|
|
#10
|
|||
|
|||
|
a little off track - but i find this "all browsers" issue to be very interesting.
i have a site that uses some features and positioning that i am not willing to compromise. and i am also willing to accept that 90% coverage is ok for this site. so i test it with IE6 and NS7. and on my first page i check to see if you support frames, javascript, and that your resolution is at leat 800*600. if not, i give you a polite message and bounce you out (don't even want you in because things just will not look right). so i think the key here is not right or wrong. but understanding what works where, so we can all make choices. |
|
#11
|
||||
|
||||
|
The problem is that that approach is often against the law in the United States. (See http://www.usdoj.gov/crt/foia/tal712.txt for the offical US Department of Justice position on the matter.) And it's a good thing too, for without that push most wee authors wouldn't even consider making sure their pages are accessible to persons with diasabilities who might be using assistive technologies.
The trick isn't to eschew the use of positioning and client side scripting but to employ it in a way that the page 'fails safe' when the positioning or scripting isn't there. |
|
#12
|
|||
|
|||
|
its a good thing the site i am talking about is not subject to ADA or any other government intrusion (good or bad).
your point is a good one, which i think reinforces what i was saying: "the key here is not right or wrong. but understanding what works where, so we can all make choices." that is one consideration in the list when making your choices. |
|
#13
|
|||
|
|||
|
Re: onClick="javascript: function('value');" or onClick="function('value');"?
Quote:
|
|
#14
|
|||
|
|||
|
Quote:
__________________
// Stefan Huszics |
|
#15
|
|||
|
|||
|
Quote:
As I already stated, Charles even posted examplecode in this very thread. Quote:
As for the proof that it's invalid, check the link to the HTML spec provided by Charles. It specifies exactly what you are alowed to do. Anything else that is not in the spec is NOT alowed. That's the entire point with having a spec to begin with...
__________________
// Stefan Huszics |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 2 (0 members and 2 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|