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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:25:53+00:00 2026-05-25T12:25:53+00:00

I have a jquery/ajax form that has event.preventDefault() . The problem is that my

  • 0

I have a jquery/ajax form that has event.preventDefault(). The problem is that my input field doesn’t go empty once I press enter. Usually when you press enter in an input field, it will do the ‘action’ in the form and the input field empties. But now when I type something, my form doesn’t reset to empty when I press enter. I know that event.preventDefault() doesn’t do the normal “action” in the form, but I’m trying to not refresh my page and just use ajax so it will load without page refresh.

——————–jquery——————– (below)

$('[placeholder]').parents('form').submit(function(event) {
  $(this).find('[placeholder]').each(function() {
    var input = $(this);
    if (input.val() == input.attr('placeholder')) {
      input.val('');
    }

  });
  var input = $('input.sel').val();
  dataList = 'list=' + input;
    $.ajax({
        type: "POST",
        url: "ajax_table_edit.php",
        data: dataList,
        cache: false,
        success: function(html)
            {
                $('.selector').html(data);
            }
    });
    event.preventDefault();

});

—————ajax_table_edit.php———– (below)

if(isset($_POST['list'])){
$list = $_POST['list'];
$id = $_POST['id'];
$id = ereg_replace("[^0-9]", "", $id);

$sql = mysql_query("INSERT INTO table (column) VALUES ('".$list."')");

echo "success";

}

At the same time. I’m trying to echo out success, but that’s not working either. Can someone help me seek the solution to this problem?

Thank you for your time!

  • 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-25T12:25:54+00:00Added an answer on May 25, 2026 at 12:25 pm

    You’ll have to blank the fields yourself with jQuery: $("#field").val='';

    And its not outputting your message, because you’re not grabbing the right variable on success.. you define it as html which may be reserved anyways… try calling it data instead because that is what you’re using inside the function anyways.

    ...
    success: function(data)
               {
                   $('.selector').html(data);
               }
    ...
    

    Also, why do you even have that $id code in the php side? looks like it doesn’t even get used. And, just because its ajax doesn’t mean you’re safe from SQL injection, you need to sanitize that $_POST['list'] variable.

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

Sidebar

Related Questions

I have a form that submits a jQuery .ajax event every time menu's value
I have a form that uses jQuery to submit an ajax post and it
I have some jQuery code. I have called an Ajax function file, file.php, that
Is it possible that using jQuery, I cancel/abort an Ajax request that I have
I have a page that has a Contact Form slide down when a link
I have a username textbox on a form, that has a few validation rules
I'm using Rails 2.3.8 and have a jQuery AJAX form using posted using: jQuery.fn.submitWithAjax
I have done jQuery and Ajax, but I am not able to get the
Let's say I have the following jQuery AJAX call: $.ajax({ type: POST, url: MyUrl,
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file

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.