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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:13:29+00:00 2026-05-28T06:13:29+00:00

I want to perform an onclick and onsubmit at the same time, is this

  • 0

I want to perform an onclick and onsubmit at the same time, is this possible? Or if this is bad practice how can I merge the two codes to perform both events?

I have this piece of code checking a mandatory field on the form tag:

onsubmit="return formCheck(this);"

I then have this piece of code on the submit button for the same form:

onClick="jQuery.facebox({ ajax: (\'wishlist.php?emailme=true&name=\' + this.form.name.value + \'&country=\' + this.form.country.value + \'&email=\' + this.form.email.value + \'&department=\' + this.form.department.value) }); return false;"

The problem I have is that on clicking the submit button it completely ignores the onsubmit code. How can I merge them together?

UPDATE I want it to check the mandatory fields first then send the form if all is ok.

UPDATE: I’ve pasted the whole code here, I’m really struggling as this was done by a previous developer. If someone could literally put the solutions into the code that would be great. I’ll up the reward.

  • 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-28T06:13:30+00:00Added an answer on May 28, 2026 at 6:13 am

    Put your onClick code in the same function as the onSumbit code.

    UPDATE

    At the end of your onClick code you return false;, this stops the normal propagation of events and stops the onSubmit event from firing. So if you want the submit button to submit the form, remove return false; from it’s onClick handler.

    When you click a submit button you will fire a click event on the button and a submit event on the form in which the button is nested (unless you stop the propagation of events with something like return false;).

    So you really only need a submit event handler that does the job of both of your current handlers.

    Also since it appears that you have jQuery Core included in your page you can attach event handlers like this:

    $(function () {
        $('#form-id').on('submit', function () {
            var $this = $(this);//$this refers to the form that is being submitted
            jQuery.facebox({
                ajax : 'wishlist.php?emailme=true&name=' + $this.find('#name').val() + '&country=' + $this.find('#country').val() + '&email=' + $this.find('#email').val() + '&department=' + $this.find('#department').val()
            });
    
            //now we run your normal onSubmit code and return it's return value of this event handler
            return formCheck(this);
        });
    });
    

    If you are sending the whole form to the jQuery.facebox function then you can use jQuery’s .serialize() function to create the necessary query-string:

    $(function () {
        $('#form-id').on('submit', function () {
            jQuery.facebox({
                ajax : 'wishlist.php?' + $(this).serialize()
            });
    
            return formCheck(this);
        });
    });
    

    Here is a demo: http://jsfiddle.net/vAFfj/

    Docs for .serialize(): http://api.jquery.com/serialize

    Note that .on() is new in jQuery 1.7 and in this case is the same as .bind() of older versions.

    UPDATE

    If you want to check the return value from the formCheck() function before running the facebox plugin then you can do this:

    $(function () {
        $('#form-id').on('submit', function () {
    
            //check if the form data is valid
            if (formCheck(this) === true) {
    
                //if the form data is valid then run the facebox plugin
                jQuery.facebox({
                    ajax : 'wishlist.php?' + $(this).serialize()
                });
    
                //also return true to stop running this function
                return true;
            }
    
            //if the form data is not valid then return false to stop the submission of the form
            return false;
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use the same button to perform 2 different methods. One method
I have button and onClick I perform opening of a new activity like this:
Hi i have have this form that i do no want to perform an
I want perform a easy task in android, which when receiving a call the
I want to perform an jquery request to php and then I want php
I want to perform action on change in count of rows of an HTML
I want to perform calculations for each company number in the column PERMNO of
I want to perform a segue, after a assync call to a service. In
I want to perform a sort operation on some field. Is it advantageous making
I want to perform changes in the code which was developed using iOS 3.0,

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.