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 8460203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:32:28+00:00 2026-06-10T13:32:28+00:00

I have been searching for an answer to this question for some time now,

  • 0

I have been searching for an answer to this question for some time now, with no luck. It may be an easy one for some of you to answer.

In this tag:

<form method="post" action="" class="jcart" id="somethinghere" onsubmit="return validate(this)">

what does the ‘this’ keyword represent?

For example, if I wanted to call the ‘validate’ function on this form from inside another javascript function, how would I do it?

I know it is like this:

<script type='text/javascript'>
function MyTest(){
validate(???);
}
</script>

but I don’t know what I should put inside the call to the validate function.

EDIT

Here’s what I’m trying to do.

I have a form that is submitted via Ajax. It also has some validation on it as well. However, the validation script is usually called when the form is submitted. However, the Ajax function already gets the ‘click’ of the submit button and submits the data, so the form is never ‘submitted’ in a way to trigger the validation.

I have found this piece of code, which is responsible for submitting the form via Ajax.

    $('.jcart').submit(function(e) {
        add($(this));
        e.preventDefault();
    });

So, I want to be able to run the validation function from there, and only call the add() function if the validation passes. But I don’t know how to call the function from here, because I don’t know how to reference the form to get the same element reference as the ‘this’ in the onsubmit call.

EDIT 2

I tried this:

$('.jcart').submit(function(e) {
    if(validate(document.getElementById("somethinghere"))){
        alert("validated");
        add($(this));
        e.preventDefault();
    }
    else {
        alert("not validated");
        e.preventDefault();
    }
});

but I get a ‘validate is not defined’ error.

Also, the code above is loaded at the end of the document, and the file with the validate function is called at the beginning. So I would have thought that the validate function would be available when I try to call it here, because it should be loaded already.

  • 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-06-10T13:32:30+00:00Added an answer on June 10, 2026 at 1:32 pm

    In that situation this represents the element the event occurred for, i.e., for the form element.

    If you want to call validate() from somewhere else but have it validate that same form then just get a reference to the form with .getElementByid() and pass that:

    function MyTest(){
      validate(document.getElementById("somethinghere"));
    }
    

    (Where “somethinghere” is your form’s id.)

    EDIT: Regarding your edits:

    “I have found this piece of code, which is responsible for submitting the form via Ajax.”

        $('.jcart').submit(function(e) {
            add($(this));
            e.preventDefault();
        });
    

    Are you sure that is responsible for submitting the form via Ajax? It would appear to be creating a submit handler on a form with the class “jcart”, and the form you showed initially doesn’t have that class. Unless the add() function that you don’t show submits the “somethinghere” form?

    “but I get a ‘validate is not defined’ error.”

    If the inline submit="return validate(this);" works on the same page then validate() would have to be a global function so you could call it from anywhere on the page. If this doesn’t work there must be more going on with your code than you’ve shown.

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

Sidebar

Related Questions

I have been searching the internet wildly for an answer to this question. We
I have been searching the answer to this question for a while. It seemed
I have been searching desperately for an answer to this question, but not found
I have been searching for an answer to this question for days and it
I have been searching everywhere for an answer to this question. I have an
I have been searching and searching for an answer to this question but with
This question might seem strange but I have been searching for an answer for
I have been searching for an answer and trying out stuff for days now
I have been searching for an answer for a couple days now and had
I have been searching here for some time but haven't been able to find

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.