Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6880043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:55:26+00:00 2026-05-27T04:55:26+00:00

So I’ve condensed my problem into a snippet of HTML code for you guys

  • 0

So I’ve condensed my problem into a snippet of HTML code for you guys to try out on your own.

I believe this was working in Firefox 3.6 but in more recent releases it no longer seems to work. It also doesn’t work in IE9 or Firefox Nightly.

    <html>
    <head>
    <title>Test</title>
    </head>
    <script type="text/javascript">
    function newEvent() {
        var myEvent = document.createEvent("MouseEvents");
        myEvent.initEvent("click", false, false);
        getElementById('Test').dispatchEvent(myEvent);
    }
    </script>
    <body>
    <form action="" onSubmit="newEvent();return false;">
      <input name="OK" type="submit" value="OK" />
      <input id="Test" name="Test" type="button" onClick="alert('Success!');" value="Test" />
    </form>
    </body>
    </html>

The problem I’m getting is that the form is being submit to the page, when I don’t want it to be. I’ve tried “return false;”, I’ve tried “event.preventDefault();”. If you comment the dispatchEvent line, everything else works as expected. I’m lead to believe that for some reason dispatching a new event (the click) seems to allow the onSubmit event to continue.

You can test yourself by clicking “OK”, which should fire onSubmit. Expected behaviour would be that a click event is generated for the “Test” button, then the onSubmit event is cancelled by the “return false;” section.

Any insight would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:55:26+00:00Added an answer on May 27, 2026 at 4:55 am

    You are missing something in your code:

    document.getElementById()
    

    See the third line:

    function newEvent() {
        var myEvent = document.createEvent("MouseEvents");
        myEvent.initEvent("click", false, false);
        document.getElementById('Test').dispatchEvent(myEvent);
    }
    

    http://jsfiddle.net/csrn5/2/

    In newEvent(), the third line needs document.. So what’s happening is you’re getting an error and that error is stopping the JS before it gets to the return false.

    Another way of demonstrating the problem:

    function newEvent() {
        try {
            var myEvent = document.createEvent("MouseEvents");
            myEvent.initEvent("click", false, false);
            getElementById('Test').dispatchEvent(myEvent);
        } catch(e){
            alert(e)
        }
    }
    

    http://jsfiddle.net/csrn5/4/

    Note, fix the error, I just wanted to show you that that was the actual problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.