Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

progmatically clicking an image button

3 views
Skip to first unread message

Duwayne

unread,
Aug 26, 2003, 10:02:24 PM8/26/03
to
I have an image button in a form -- <input type="image"> -- and I need
to be able to progmatically click this via javascript from another
frame. How can this be done?

asdf asdf

unread,
Aug 27, 2003, 1:12:14 AM8/27/03
to
I guess there are two problems here:
1) cross-frame scripting
2) programatically clicking something

I'll give my input on (2). Assuming your input has a name and is in a
uniquely named form, once you have solved (1), you can (in ie6 at
least) get the form out of the forms collection, then get the named
input out of the form's collection of inputs, and call "click()" or
"fireEvent(eventname)" or, if you need an x and y coordinate, in IE,
you can fabricate an event object and fire it
"yourinput.fireEvent(eventname,eventobj)"

http://msdn.microsoft.com/workshop/author/dhtml/reference/objects.asp

dm...@yahoo.com (Duwayne) wrote in message news:<617da882.03082...@posting.google.com>...

Csaba2000

unread,
Aug 28, 2003, 2:30:50 AM8/28/03
to
Dear Mr. Anonymous,

I have attempted to use fireEvent, but failed.
See my earlier post and replies on this subject at:
http://groups.google.com/groups?th=c2dee59926880f52

What happened with fire event was that the image
object was happy enough with it, but submit ignored
the constructed mouse coordinates. Very irritating,
and I never figured it out. I'd love to see a solution to it.

Csaba Gabor from New York.


"asdf asdf" <b0b...@yahoo.com> wrote in message news:6f24588b.03082...@posting.google.com...

Duwayne Sy

unread,
Aug 28, 2003, 1:32:37 PM8/28/03
to
Well i figured out how to do it. But the reason why I need a javascript
that simulate clicking the button is because I am using ASP.NET and need
the proper event to be fired at the back end. The page being submitted
in on one frame and another page that is going to do the submition is on
anther frame so I need need to go to the client side and do a submit
through the button so the propery asp.net event will be fired on the
back end.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Csaba2000

unread,
Aug 29, 2003, 4:14:40 AM8/29/03
to
Hi Duwayne,

Please do share the basics of how you finally did it.
It may help someone later.

Regards,
Csaba Gabor from New York

"Duwayne Sy" <dm...@yahoo.com> wrote in message news:3f4e3cb4$0$62083$7586...@news.frii.net...

Csaba2000

unread,
Aug 29, 2003, 4:36:30 AM8/29/03
to
Hi Fred,

Yes, I had not replied earlier to those posts because I didn't know
about them and mail delivery times delayed my registration at Google.
I think the original poster's issues are somewhat different from mine,
and I'll detail mine at the end, but something that I look for is that the
solution should be generic.

<input type="image"> and <input type="submit"> behave differently.
The former appends an &x=xCoordinate&y=yCoordinate to the end
of whatever is submitted to the server while the latter does not.
However, the only solution I know of (posted by Dom) does use
form.submit (and he constructs the x and y elements to append).

The problem, as I mentioned in my older post, is that while you can
construct the event that you want, the final submit doesn't quite
believe the actual mouse event and while it will do the submit, it
won't transmit the desired (constructed) coordinates.
The second idea is fine for specific situations, but I think falls short
as a generic solution. For example, what do you do if the submission
method is POST? Also, you should hook in carefully to the existing
handlers, which may themselves be altering form variables. This
approach seems dicey for my purposes.

However, the ideas are appreciated very much. This has been a
nasty problem to get a handle on and for most situations, the extreme
I'm after is not warranted.

I have updated the earlier thread with my reasons for wanting the
programmatic image button clicking, and I'll copy them here:

I want to run IE in the background. Running apps in the
background is a normal and usual thing to do. Specifically,

I am invoking IE and accessing its DOM through VB (hence my
restriction to IE). Then I put IE through its paces by loading pages
and simulating user interactions via the DOM. [Philosophy: I don't
see any inherent reason for IE to imagine that it is within windows
or any particular environment. I want to think of IE as a black box].
For example, once a month, I want to pay my Sprint phone bill.
Sprint's final confirmation depends on actually clicking (with a
mouse!) an INPUT type=image element. So I need to simulate that somehow.

Now if Windows strongly enforces an app having to have focus before
it accepts mouse clicks, IE is even more so. It's probably possible,
but I have not yet been able to simulate mouse clicks to IE without
bringing it to foreground, and I have asked about this extensively in
the relevant VB and WinAPI newsgroups. So I try other avenues, and the
preferred one (even more so than simulating the clicks) is to use the DOM.

This total simulation is also why performing an explicit http
request in this context is not reasonable. To do that, you
should analyze the page to figure out what needs to be
submitted (the point being that we really don't know ahead
of time since we're talking generic simulation of IE usage).
This generally needs to be done manually on a page by page basis.
I don't think it's reasonable to do it programmatically
since you'd have to ensure that you're the very last
handler mucking with the page. And IF you get that part
right, you're still on the hook to do something with the
values you figured out.

So, to restate, I am able to simulate all standard (I say
standard because I haven't gotten around to things like
save image, etc.) DOM user interaction with IE using the
usual DOM methods EXCEPT for explicit mouse clicking where
coordinates are produced. That would be INPUT type=image
elements and server side image maps. So I have tried to
isolate only the essential features related to javascript
so that readers would not be overwhelmed (because past
experience has also shown that the longer a question is,
the smaller the liklihood is that it gets answered).

Regards from New York,


Csaba Gabor from New York


"Fred Basset" <fred....@whosyourdaddy.com> wrote in message news:3f4db71b$0$62082$7586...@news.frii.net...
> I'm not entirely certain what you're trying to achieve here. You really
> need (as it said in the last thread) to be more specific about why you
> want what you are requesting. Often the solution lies not in the first
> question but by altering something further back (or possibly that the
> further information about the environment suggests a solution for the
> immediate question).
>
> I see a couple of things that you could bear in mind, although not
> knowing the full details I can't tell if they would work or not.
>
> First of all, an <input type="image"> is ultimately the same as an
> <input type="submit"> in that both perform the same function. You could
> call form.submit() to achieve the button.click event as well.
>
> The mouse co-ordinates could be achieved by doing a little discovery
> work on the input itself. If you get the top and left co-ordinates of
> the input and then add half the height and width then you'll have the
> correct co-ordinates ... you could use something like this to get the X
> value of the left of the input for example ...
>
> function getX(oTarget)
> {
> var intReturnX = 0;
> while(oTarget!=null)
> {
> intReturnX += oTarget.offsetLeft;
> oTarget = oTarget.offsetParent;
> }
> return intReturnX;
> }
>
> How you actually get the co-ordinates through to your event handlers is
> up to you, but if you can do so and then call a submit() on the form
> then the problem will be solved.
>
> My final idea is similar to the one above, but instead of calling a
> function to submit the form merely call it using a custom-built URL,
> e.g.
>
> location = "http://www.domain.com/myform.cgi?x=4&y=3&me=old"
>
> Where you bypass the submit() event but still provide the form handler
> with all the necessary parameters.
>
> Hope something from all that helps.
>
> Fred Basset
> fred....@whosyourdaddy.com

Duwayne Sy

unread,
Aug 29, 2003, 1:02:36 PM8/29/03
to
All I did was find out if ASP.NET will fire the proper event if I
transmit the imageid.x and imageid.y name value pairs. It does, so
during submission from the submitting frame I call a function on the
frame that is going to be submitted and include 2 new hidden fields with
random x and y values, then I submit.
0 new messages