/    Sign up×
Community /Pin to ProfileBookmark

Remotely clicking a submit button

I have two frames:

<frameset rows=”50%,*”>
<frame name=”one” src=”one.html”>
<frame name=”two” src=”two.html”>
</frameset>

Frame two has a submit button for a form.

I want to be able to click that submit button from frame one using javascript.

Here is the code I used:

onClick=”top.two.formName.submit.click();”

This works great in IE. I cannot get it to work in Netscape, even Netscape 7.1.

What am I doing wrong, or how can I get it to work in Netscape?

Thanks.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@NedalsApr 24.2004 — onClick="top.two.formName.submit.click();"[/quote]
That works in IE ?? Strange!

It should read...

onclick="top.two.formName.submit();"

or is it...

onclick="top.two.document.formName.submit();"
Copy linkTweet thisAlerts:
@comasterauthorApr 25.2004 — Thanks nedals for the response,

All I wanna do is be able to click a button programmatically. It doesn't have to be a submit button.

So, if I have:

<input type="button" name="mybutton">

The right js code would be

onClick="top.two.formName.mybutton.click();"

This works in IE, and I don't think it's an unreasonable coding requirement.
Copy linkTweet thisAlerts:
@fredmvApr 25.2004 — You have to use something called synthetic events to get it working in Mozilla. Take the following example for instance:&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt;
&lt;head&gt;
&lt;title&gt;untitled&lt;/title&gt;
&lt;meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" /&gt;
&lt;script type="text/javascript"&gt;
//&lt;![CDATA[
function fireEvent()
{
var e = document.createEvent('MouseEvents');
e.initEvent('click', true, false);
document.getElementById('foo').dispatchEvent(e);
}

<i> </i> onload = function()
<i> </i> {
<i> </i> setTimeout(fireEvent, 3000);
<i> </i> }
<i> </i> //]]&gt;
<i> </i> &lt;/script&gt;
<i> </i>&lt;/head&gt;
<i> </i>&lt;body&gt;
<i> </i> &lt;h1 onclick="alert('event fired!');" id="foo"&gt;Firing &lt;code&gt;onclick&lt;/code&gt; event in 3 seconds&lt;/h1&gt;
<i> </i>&lt;/body&gt;
&lt;/html&gt;
Alternatively, you could add a [font=courier]click[/font] method onto all [font=courier]HTMLElement[/font] objects:if(typeof HTMLElement != 'undefined')
HTMLElement.prototype.click = function()
{
// thanks to Jason Davis for the following code
var evt = this.ownerDocument.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt);
}
Which would then allow you to use it just like you would in IE.
Copy linkTweet thisAlerts:
@comasterauthorApr 25.2004 — fredmv thanks. I'll give that a try. Unbelievable how much one has to improvise just to accomplish something so simple.
×

Success!

Help @comaster spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...