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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:07:29+00:00 2026-05-22T21:07:29+00:00

I have a simple form for users to post on a ‘wall’. As you

  • 0

I have a simple form for users to post on a ‘wall’. As you can see it has one text input field and a submit button that is made of multiple spans styled via CSS.

<form action="http://example.com/2/chat_share" method="post" id="chat_form">                    
<input type="text" name="chat_msg" value="" />                  
</form>

<span class="share_js fc-button fc-button-prev fc-state-default fc-corner-left fc-corner-right">
    <span class="fc-button-inner">
        <span class="fc-button-content save_button">Share</span>
        <span class="fc-button-effect">
            <span></span>
        </span>
    </span>
</span>

This works nicely when the user clicks on the ‘Share’ button, which runs the AJAX below:

$(document).ready(function() {

    $('.share_js').click(function(event){
        event.preventDefault();

        var link = $('#chat_form').attr('action');

        $.ajax({
            url: link,
            type: "POST",
            data: $('#chat_form').serialize(),
            dataType: "html",
            beforeSend: function(){
                  $('#loading').show();
                },          
            success: function() {
                $('#chat_thread').load(2 + '/chat_ajax');
                $('#loading').hide();
                $('#chat_form input').val('');
            }
        });
    });

});

My problem is that when I hit ‘return’ or ‘enter’ on the keyboard, the form is submitted via the non-AJAX method.

I wanted to capture this keystroke using

$('#selector').keydown(function (e){
    if(e.keyCode == 13){
        //code
    }
})

but haven’t been able to wrap this around my AJAX function.

Ideally both clicking on Share and hitting return should submit the form.

Anyone have suggestions how to do this?

Thanks for helping!

  • 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-22T21:07:30+00:00Added an answer on May 22, 2026 at 9:07 pm

    why not using the form post?

    <form action="http://example.com/2/chat_share" method="post" id="chat_form">                    
    <input type="text" name="chat_msg" value="" />                  
    
    <span class="share_js fc-button fc-button-prev fc-state-default fc-corner-left fc-corner-right">
        <span class="fc-button-inner">
            <span class="fc-button-content save_button">Share</span>
            <span class="fc-button-effect">
                <span></span>
            </span>
        </span>
    </span>
    </form>
    

    and then hook up the form POST

    $('#chat_form').bind('submit', function(event) {
    
        var link = $(this).attr('action');
    
        $.ajax({
            url: link,
            type: "POST",
            data: $(this).serialize(),
            dataType: "html",
            beforeSend: function(){
                  $('#loading').show();
                },          
            success: function() {
                $('#chat_thread').load(2 + '/chat_ajax');
                $('#loading').hide();
                $('#chat_form input').val('');
            }
        });
    
        return false; // dont post it automatically
    });
    

    from comments

    $('.save_button').bind('click', function(event) {
        getStuff();
        return false; // dont move to top
    });
    $('#chat_form').bind('submit', function(event) {
        getStuff();
        return false; // dont post it automatically
    });
    
    function getStuff() {
    
        var link = $('#chat_form').attr('action');
    
        $.ajax({
            url: link,
            type: "POST",
            data: $('#chat_form').serialize(),
            dataType: "html",
            beforeSend: function(){
                  $('#loading').show();
                },          
            success: function() {
                $('#chat_thread').load(2 + '/chat_ajax');
                $('#loading').hide();
                $('#chat_form input').val('');
            }
        });
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
I have a very simple form where users can enter their email and click
I have a simple db.Model , that has one of the fields db.ListProperty(users.User) For
I have a simple comment section where users can post comments to another users
We have a simple registration form for our website users where we only require
I have an application writted in ASP with a simple form. The users fill
I have a simple form with some plain html input like bellow using ASP.NET
I have a simple form that looks like so <% remote_form_for post, :url =>
I have a simple contact form which uses jquery to post to a php

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.