log in | register | forums
Show:
Go:
Forums
Username:

Password:

User accounts
Register new account
Forgot password
Forum stats
List of members
Search the forums

Advanced search
Recent discussions
- Elsear brings super-fast Networking to Risc PC/A7000/A7000+ (News:)
- Latest hardware upgrade from RISCOSbits (News:)
- RISCOSbits releases a new laptop solution (News:4)
- Announcing the TIB 2024 Advent Calendar (News:2)
- RISC OS London Show Report 2024 (News:1)
- Code GCC produces that makes you cry #12684 (Prog:39)
- Rougol November 2024 meeting on monday (News:)
- Drag'n'Drop 14i1 edition reviewed (News:)
- WROCC November 2024 talk o...ay - Andrew Rawnsley (ROD) (News:2)
- October 2024 News Summary (News:3)
Latest postings RSS Feeds
RSS 2.0 | 1.0 | 0.9
Atom 0.3
Misc RDF | CDF
 
View on Mastodon
@www.iconbar.com@rss-parrot.net
Site Search
 
Article archives
Acorn Arcade forums: Programming: Javascript events
 
  Javascript events
  monkeyson2 (11:40 25/8/2004)
  Phlamethrower (19:20 25/8/2004)
  Matthew (19:57 25/8/2004)
    monkeyson2 (20:01 25/8/2004)
      tribbles (21:38 25/8/2004)
        Matthew (22:04 25/8/2004)
          monkeyson2 (22:13 25/8/2004)
 
Phil Mellor Message #57526, posted by monkeyson2 at 11:40, 25/8/2004
monkeyson2Please don't let them make me be a monkey butler

Posts: 12380
If you've got a function that takes a parameter

function example(foo)
{
window.alert(foo);
}

In a tag you can do something like this

<li id="li1" onmouseover="example('bar')">...</li>

How would you do it within a function?

As far as I can tell you can only do
li1.onmouseover = example;

Is there any way to specify the parameter too?
  ^[ Log in to reply ]
 
Jeffrey Lee Message #57540, posted by Phlamethrower at 19:20, 25/8/2004, in reply to message #57526
PhlamethrowerHot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot stuff

Posts: 15100
As a rough guess, I'd say li1.onmouseover = "example('bar')";
  ^[ Log in to reply ]
 
Matthew Somerville Message #57543, posted by Matthew at 19:57, 25/8/2004, in reply to message #57526
Matthew

Posts: 520
li1.onmouseover = example;
I think you mean document.getElementById( "li1" ).onmouseover = example; ? :)
Is there any way to specify the parameter too?
I don't believe so; the only thing passed to the example function will be an event object. You could put the variable you want in an attribute (e.g. class="bar" ), and then use the event object to get at that value. A bit roundabout, any reason you can't put the call in the element?
  ^[ Log in to reply ]
 
Phil Mellor Message #57544, posted by monkeyson2 at 20:01, 25/8/2004, in reply to message #57543
monkeyson2Please don't let them make me be a monkey butler

Posts: 12380
A bit roundabout, any reason you can't put the call in the element?
Because there are about 60 elements that need onmouseover and onmouseout events - which means the html file is too big.

My first plan was to apply the onmouseout event in the function that calls the onmouseover event -- thus halving the space required.
  ^[ Log in to reply ]
 
Jason Tribbeck Message #57552, posted by tribbles at 21:38, 25/8/2004, in reply to message #57544
tribbles
Captain Helix

Posts: 929
My first plan was to apply the onmouseout event in the function that calls the onmouseover event -- thus halving the space required.
How about keeping an array of IDs to parameters? I think - can you get the ID of the item being clicked on/off?
  ^[ Log in to reply ]
 
Matthew Somerville Message #57554, posted by Matthew at 22:04, 25/8/2004, in reply to message #57552
Matthew

Posts: 520
<script type="text/javascript"> 

function onmouseover(e) {
/* Cookie-cutter code to find the source of the event */
if (typeof e == 'undefined') {
var e = window.event;
}
var source;
if (typeof e.target != 'undefined') {
source = e.target;
} else if (typeof e.srcElement != 'undefined') {
source = e.srcElement;
} else {
return;
}
/* End cookie-cutter code */

/* DO STUFF HERE */

}

(Taken from http://www.sitepoint.com/article/simple-tricks-usable-forms.)
I think you should be able to do what you want, monkeyson, might involve some lateral thinking. :)
  ^[ Log in to reply ]
 
Phil Mellor Message #57556, posted by monkeyson2 at 22:13, 25/8/2004, in reply to message #57554
monkeyson2Please don't let them make me be a monkey butler

Posts: 12380
Ooh, is that an advanced form of 'this' ?

That might be just what I need. I will try it tomorrow :)
  ^[ Log in to reply ]
 

Acorn Arcade forums: Programming: Javascript events