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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:04:09+00:00 2026-06-03T03:04:09+00:00

i have a form (made through codeigniter) that i want to submit with ajax

  • 0

i have a form (made through codeigniter) that i want to submit with ajax onClick. Form submits without Ajax and doesnt let me do event.preventDefault();

jQuery file

$('#register_submit').click(function(e){//
   e.preventDefault();
    var first_name = $('#register_form1').val();


    $.ajax({
        type: "POST", 
        async: false, 
        url: base_url+"register/registration_val",   
        data: "register_first_name="+first_name,
        success: function(data){
            $('#inferiz').html(data);
        },
        error: function(){alert('error');}
    }); 

});

// Controller works just fine. name register, function that i POST to is registration_val

HTML file

 <form method="POST" action='<?php echo site_url('/register/registration_val'); ?>' id='register_form' >
   <input type="login" name="register_first_name" id="register_form1">
   <input type='submit' value="Register" id='register_submit'>
 </form>

Problem is, when I click on SUBMIT button, jQuery doesnt do its work, instead, form submits itself to the controller and gives out an ERROR message.
I cannot prevent the form from submitting (which i think would solve the problem), the Click event is completely ignored.
Thanks in advance

  • 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-03T03:04:10+00:00Added an answer on June 3, 2026 at 3:04 am

    Try your luck with the submit event instead of click:

    $('form').submit(function(e){//
       e.preventDefault();
        var first_name = $('#register_form1').val();
    
    
        $.ajax({
            type: "POST", 
            async: false, 
            url: base_url+"register/registration_val",   
            data: "register_first_name="+first_name,
            success: function(data){
                $('#inferiz').html(data);
            },
            error: function(){alert('error');}
        });     
    });
    

    If the from has an id replace 'form' with '#{formId}'.

    Notes:

    • The code should be inside a DOM ready event callback.
    • If the form doesn’t exist on DOM ready, you should use delegate event.

    Like with this:

    $('body').on('submit', 'form', function(e){
       e.preventDefault();
        var first_name = $('#register_form1').val();    
    
        $.ajax({
            type: "POST", 
            async: false, 
            url: base_url+"register/registration_val",   
            data: "register_first_name="+first_name,
            success: function(data){
                $('#inferiz').html(data);
            },
            error: function(){alert('error');}
        });     
    });
    

    Just replace body with a closer static element (if there is one) to enhance performance.

    Good Luck!

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

Sidebar

Related Questions

I have made a form that accepts query and executes it through php. I
In my iOS application I have made a form that should submit data into
I have a dynamic form that adds users to the site, made so you
I have started using jQuery and rails. I have made a simple form that
I have a event model that has many invitations. Invitations are setup through checkboxes
I have a registration form on my layout grid, made out of a stackPanel.
I have made a Base Form which is inherited by most Forms in the
I have made a simple web form in Google app engine where I have
i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big
Post-release, I have made one small change to one form in our development site

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.