List Info

Thread: Clicking a Button Programmatically




Clicking a Button Programmatically
user name
2006-05-24 04:03:50
I've read section 4.22 of the Dive Into Greasemonkey book. 
But I'm looking at a 
form with a regular button, rather than a submit.  So how do
I fire an onClick 
event?

If it helps, here's the HTML:

<input value="Refresh"
onclick="airtimeDetailForm.submit()"
type="button">

Thanks for your help,
-- 
A. Alfred Ayache
http://lphs76.ca            
- Reunion community
http://www.rentersPlus.com
   - Apartment Search
http://www.lastbyte.ca 
     - Web Design, eCommerce, PHP/MySQL, Java, Oracle
_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
Clicking a Button Programmatically
user name
2006-05-24 05:00:06
Hello,

On 5/23/06, A. Alfred Ayache <alfredlastbyte.ca> wrote:
>
> I've read section 4.22 of the Dive Into Greasemonkey
book.  But I'm
> looking at a
> form with a regular button, rather than a submit.  So
how do I fire an
> onClick
> event?
>
> If it helps, here's the HTML:
>
> <input value="Refresh"
onclick="airtimeDetailForm.submit()"
type="button">
>

Using "onclick" should work.


Perhaps you have a syntax error or something.  Try looking
at the JavaScript
console to see if some error shows.


See ya

-- 
    Charles Iliya Krempeaux, B.Sc.

    charles  reptile.ca
    supercanadian  gmail.com

    developer weblog: http://ChangeLog.ca/
____________________________________________________________
_______________
 Make Television                                http://maketelevision.com/

_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
Clicking a Button Programmatically
user name
2006-05-24 06:25:49
> I've read section 4.22 of the Dive Into Greasemonkey
book.  But I'm 
> looking at a form with a regular button, rather than a
submit.  So how 
> do I fire an onClick event?
> 
> If it helps, here's the HTML:
> 
> <input value="Refresh"
>     onclick="airtimeDetailForm.submit()"
>     type="button">


If you're just firing a submit event anyway, one might ask
why you're 
not just using a normal "submit" button...

But anyway, try "onClick", instead of
"onclick". Just a guess. Might work.

- Andrew
_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
Clicking a Button Programmatically
user name
2006-05-24 08:07:46
Hi Alfred,

if 'elem' is your button, you need to do the following:

evt=document.createEvent("MouseEvents");
if(evt && evt.initMouseEvent) {
      
evt.initMouseEvent("click",true,true,document.de
faultView,
                         
1,0,0,0,0,false,false,false,false,0,null);
       elem.dispatchEvent(evt);
}

(Code received from Jeremy (I think) some months ago.
Thanks!!)

Beware that somewhere on Mozilla.org the documentation on
clicking 
buttons is (or was) just wrong. I forgot the link to the
good 
documentation :-(

The "onclick" attribute is not directly
accessible due to the nature of 
the wrappers around all page objects (see Mark's wonderful
book "Dive 
Into Greasemonkey book" about details on wrappers).

Calling (or evaluating) the contents of the onclick
attribute is a 
security risk, because the called (evaluated) code would be
executed in 
GM context with raised privileges.

Firing the click event as described above should be safe
though.

Cheers, Andre

A. Alfred Ayache wrote:
> I've read section 4.22 of the Dive Into Greasemonkey
book.  But I'm 
> looking at a form with a regular button, rather than a
submit.  So how 
> do I fire an onClick event?
> 
> If it helps, here's the HTML:
> 
> <input value="Refresh"
onclick="airtimeDetailForm.submit()"
type="button">
> 
> Thanks for your help,

_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )