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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:02:35+00:00 2026-06-12T15:02:35+00:00

I would first want to say that I am very new to javascript and

  • 0

I would first want to say that I am very new to javascript and jQuery.
Its a very silly and simple problem I suppose, and I am aware there are plenty of questions on this, and I did try all of them. Though I cant seem to solve my problem.

I have an input field and a submit button. On clicking submit I would like to save the content of the input filed into the database, and continue to remain in the same page with content on page as is.

My Javascript code is as follows:

 <script type="text/javascript">
        $(document).ready(function()
        {
            $('#submit').submit(function(e)
            {

                e.preventDefault();
                var msg = $('#uname').val();
                $.post("c_test/test_submit", {uname: msg}, function(r) {
                   console.log(r);
                });
            });
        });
    </script>

And my html code as follows ( I use codeigniter):

$this->load->helper('form');
echo form_open();
$data =array ('name'=>'uname','id'=>'uname');
echo form_input($data) . '<br />';
$data=array('name'=>'submit','id'=>'submit','value'=>'Submit');
echo form_submit($data);
echo form_close();

I would be very grateful if anyone could point out my stupidity. Thanks!

  • 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-12T15:02:36+00:00Added an answer on June 12, 2026 at 3:02 pm

    You are using

    $('#submit').submit(function(e){ ... });
    

    In this case submit is the button/input‘s id and it has no such an event like submit, instead you can use click event, like

    $('#submit').click(function(e){ ... });
    

    or

    $('#submit').on('click', function(e){ ... });
    

    Otherwise, you can change the following line

    echo form_open();
    

    to

    echo form_open('c_test/test_submit', array('id' => 'myform'));
    

    and instead of

    $('#submit').click(function(e){ ... });
    

    you can use

    $('#myform').submit(function(e){
        e.preventDefault();
        var msg = $('#uname').val();
        var url=$(this).attr('action');
        $.post(url, {uname: msg}, function(r) {
            console.log(r);
        });
    });
    

    or

    $('#myform').on('submit', function(e){
        e.preventDefault();
        var msg = $('#uname').val();
        var url=$(this).attr('action');
        $.post(url, {uname: msg}, function(r) {
            console.log(r);
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, I would like to say that I am very new to SharePoint
First I would like to say that I am new to this site, never
First I want to say that I'm really new to neural networks and I
First of all, I must say that I'm very new to Google Closure, but
I'm trying to write a function that would use its first argument, then send
First of all, I want to say sorry for this very big question, but
Well, first I want to say I'm a bit new in the world of
I would first like to admit that I am an extremely novice developer, so
From this post : I would first suggest that you optimize your dependentObservable (a.k.a.
I first have to say that I really am a rookie in caching, so

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.