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

  • SEARCH
  • Home
  • 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 7686349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:27:34+00:00 2026-05-31T19:27:34+00:00

I am trying to intercept form submits from webpages I dont control. My current

  • 0

I am trying to intercept form submits from webpages I dont control.

My current implementation is …

// During onLoad, loop through all forms and for each form object
var prevonsubmit = formobj.onsubmit;
if (prevonsubmit) {
    formobj.onsubmit = function f() {
        if(prevonsubmit()) {
            interceptform();
            return true;
        }
        return false;
    };
} else {
    formobj.onsubmit = function ff() {
        interceptform();
        return true;
    };
}

The problem with this is, inside interceptform(), I am unable to identify which form actually made this submission. Is there a way I actually get the form object that is trying to submit? Keep in mind that some of the forms I see do not have a name or id specified and there is more than one form (in the same webpage) with same action.

Edit:
The purpose is capture the content in the input tags that belong to the form.
A made up example of what I see in a form:

<form action="https://duckduckgo.com/html/" method="GET">
    <input type="text" name="q"/>
</form>
<form action="https://duckduckgo.com/html/" method="GET">
    <input type="text" name="l"/>
</form>
<form action="https://duckduckgo.com/html/" method="GET">
    <input type="text" name="l"/>
    <input type="text" name="q"/>
</form>

Edit2:

Based on @ruakh answer, the solution I ended up using:

var prevonsubmit = formobj.onsubmit;
if (prevonsubmit) 
    formobj.onsubmit = createOnSubmitFunctionWithOld(prevonsubmit, formobj);
else
    formobj.onsubmit = createOnSubmitFunction(formobj);

// Definition of the functions:
function createOnSubmitFunctionWithOld(prevonsubmit,formObj) {
    return function () {
        if (prevonsubmit()) {
            interceptform(formObj);
            return true;
        }
        return false;
    };
}
function createOnSubmitFunction(formObj) {
    return function () {
        interceptform(formObj);
        return true;
    };
}
  • 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-31T19:27:35+00:00Added an answer on May 31, 2026 at 7:27 pm

    You can simply pass formobj as an argument to interceptform():

            interceptform(formobj);
    

    But bear in mind that both with formobj and with prevonsubmit, you have to be careful to avoid capturing a variable you don’t want to. For example, in JavaScript, this:

    var functions = [];
    for(var i = 0; i < 10; ++i)
        { functions[i] = function() { return i; }; }
    

    creates ten functions that all return 10, because they all capture the same i variable that’s been incremented up to 10 by the time the functions are ever called. In the above example, you could write something like:

    function new_constant_function(return_value)
        { return function() { return return_value; }; }
    
    // ...
    
    var functions = [];
    for(var i = 0; i < 10; ++i)
        { functions[i] = new_constant_function(i); }
    

    to copy each value of i into a new local variable return_value whose value never changes; or, a bit more tersely, this:

    var functions = [];
    for(var i = 0; i < 10; ++i)
        { functions[i] = (function(_i){ return function(){ return _i; } })(i); }
    

    You’ll almost certainly need to do something similar in your case. (But without seeing a bit more of the context of your code, it’s hard to say exactly what.)

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

Sidebar

Related Questions

I'm trying to intercept an image from an HTML form's input control to convert
I'm trying to intercept all kind of form submissions for a specifc form on
I'm trying to use jQuery to intercept control-A keypresses on my web page, like
I'm trying to POST and email address entry from a HTML form to a
I'm trying to intercept the submission of a form in order to change the
I am trying to validate form data from server-side. my interest is that the
This thing is drive me crazy. I'm trying to intercept an exception server-side, during
I'm using a HtmlEditor control inside a Windows Form. I got the control from
I'm trying to implement a .net form control with functionality similar to a combo
so I'm trying to intercept a javascript form submission using jquery, and having some

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.