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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:43:26+00:00 2026-06-18T01:43:26+00:00

I have this html page with the form <form method=post id=form1 name=form1 action=/status_comment/save> //Some

  • 0

I have this html page with the form

 <form  method="post" id="form1" name="form1" action="/status_comment/save">
 //Some text inputs
 <input type="text" name="new_comment" id="new_comment" onkeydown="post_comment(event,'13')" >
 </form>

And this is my javascript function to do the POST call

 function post_comment(event,item_id)
    {
     var keyCode = ('which' in event) ? event.which : event.keyCode;
     if(parseInt(keyCode)==13 && event.shiftKey!=1)
     {
       var str = $('#form1').serialize(); // Gets all the filled details
       $.post('/status_comment/save',
       str,
       function(data){
       alert(data);
       });
    }}

Backend is done using Django and this is the return statement

data=simplejson.dumps(data)
return HttpResponse(data, mimetype='application/json')

The referral url is say “/xyz”.

The thing is, after the form gets submitted, it is being automatically redirect to the “/status_comment/save” page instead of remaining on the same page.
I tried the get method and it works fine but not the POST method.

I tried debugging it, so changed the url in post call to the referral url, then it refreshs the page instead of doing nothing.

Also the alert() command inside the function above doesnt work, so its probably not being entered into.

Interesting thing I have noticed, when looking at the web developer console, the Initiator for the POST call in this page is being displayed as “Other” while the initiator for GET call and POST call (in other pages, where its working) is “jquery-1.8.0.min.js:2”

Any thoughts? 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-18T01:43:28+00:00Added an answer on June 18, 2026 at 1:43 am

    First you really shouldn’t try to capture the enter if you can avoid it. Use the submit binding. It makes everything more obvious and easier for your fellow developers (I bet I am not the only one who thought “What the heck is KeyCode 13?”).

    I’m wondering if perhaps being more explicit might help. Have you tried calling preventDefault and stopImmediatePropagation?

    $('#form1').submit(function(evt) {
        evt.preventDefault();
        evt.stopImmediatePropagation();
        // serialize and be AJAXy yada yada yada
    

    If that doesn’t work, or for some reason you prefer to handle capturing enter on your own, then you might want to have the above code in addition to your keydown handler. So it would be:

    <input type="text" name="new_comment" id="new_comment" onkeydown="post_comment(event,'13')" >
    

    …

    $('#form1').submit(function(event) {
        event.preventDefault();
        event.stopImmediatePropagation();
    }
    
    function post_comment(event,item_id)
    {
        event.preventDefault();
        event.stopImmediatePropagation();
      var keyCode = ('which' in event) ? event.which : event.keyCode;
      if(parseInt(keyCode)==13 && event.shiftKey!=1)
      {
        var str = $('#form1').serialize(); // Gets all the filled details
        $.post('/status_comment/save',
        str,
        function(data){
          alert(data);
        });
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this as template account_form.html <form action=/contact/ method=post> {% for field in form
I have a simple form method... <form method=POST action=j_security_check> <table> <tr> <td>Name:</td> <td><input type=text
I have this HTML form page: form1.html <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd
I have this html page which is very simple, it contains a text box
I have my html-php web page with form, inputs and sumbit button. With html
I am testing Html form using post method and got this odd result: I
I have this HTML in my page <div id='masterDIV'> <div id='divItemNumber'>23</div> <div id='divDesc'>This is
I have this script on my html page: <script language='javascript'>parent.resizeTo(550,510);</script> I'd like to add
I have an html page i want to print a portion of this html
I have simple HTML page with svg like this: <div id=plan> <svg xmlns=http://www.w3.org/2000/svg version=1.1>

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.