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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:42:55+00:00 2026-06-08T06:42:55+00:00

I am currently using Ajax/JS to submit a form without a page refresh or

  • 0

I am currently using Ajax/JS to submit a form without a page refresh or button click. I have set a timer with keyup to trigger the function. I have tested it with one input field and works well but now that other input fields have been added I am getting no results echoed out by the PHP. I have checked with firefox bug tool and the results are being stored. I am not sure if this a JS or PHP issue.

How can I properly echo the value of input field after the user has stop typing? EXAMPLE

JS/AJAX

<script>
$(document).ready(function() {
  var timer = null; 
  var dataString;   
     function submitForm(){
    $.ajax({ type: "POST",
    url: "index.php",
    data: dataString,
    success: function(result){
    $('#special').html('<p>' +  $('#resultval', result).html() + '</p>');}
                                  });
               return false;
             }
          $('#contact_form').on('keyup', function() {
    clearTimeout(timer);
    timer = setTimeout(submitForm, 2000);
    var name = $("#contact_name, #email, #phone, #address, #website").val();
    dataString = 'name='+ name;
             });
             }); 
</script>

HTML/PHP Snippet

<form action="" method="post" enctype="multipart/form-data" id="contact_form" name="form4">
 <div class="row"> 
  <div class="label">Contact Name *</div> <!-- end .label -->
    <div class="input">
      <input type="text" id="contact_name" class="detail" name="contact_name" value="<?php echo isset($_POST['contact_name'])? $_POST['contact_name'] : ''; ?>" /> 
      <div id="special"><span id="resultval"><? echo $_POST['contact_name'];  ?></span></div>
    </div><!-- end .input-->
 </div><!-- end .row -->

 <div class="row"> 
  <div class="label">Email Address *</div> <!-- end .label -->
   <div class="input">
    <input type="text" id="email" class="detail" name="email" value="<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>" /> 
    <div id="special"><span id="resultval"><? echo $_POST['email'];  ?></span></div>
   </div><!-- end .input-->
 </div><!-- end .row -->
  • 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-08T06:42:56+00:00Added an answer on June 8, 2026 at 6:42 am

    Rather than trying to do a mass assignment, you’ll need to build up your data. E.g., you currently have:

        var name = $("#contact_name, #email, #phone, #address, #website").val();
    

    That jquery should match on the first identifier it matches, most likely the element with id contact_name, and that will be the only value name has, where as you’re hoping to get several form fields of data.

    In fact, you shouldn’t need to build up dataString at all, as your data will be submitted by post via the form.

    Rewriting the JS:

    $(document).ready(function() {
        var timer = null; 
        var dataString;   
        function submitForm(){
            $.ajax({ type: "POST",
                url: "index.php",
                dataType: 'json',
                success: function(result){
                $('#special').html('<p>' +  $('#resultval', result).html() + '</p>');}
                                  });
            return false;
        }
        $('#contact_form').on('keyup', function() {
            clearTimeout(timer);
            timer = setTimeout(submitForm, 2000);
        });
    }); 
    

    In your index.php, you can then access the form values in the $_POST array, e.g. $_POST[‘contact_name’].

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

Sidebar

Related Questions

I am currently using Ajax to submit an input field without a page refresh
I have a basic form that I would like to submit using ajax, without
Any way to submit a form without refreshing the current page at all using
I'm currently using form.serialize() in an ajax request to submit a contact form, but
Currently, I am using an with ajax to update my mysql. Now, I have
I want to render a form (fields and includes a submit button) when using
I am at a loss. I submit a form via Ajax using submitForm: function(element)
I have a form with two buttons, a submit button and a cancel/close button.
I am using a function that will submit with ajax and without the help
Here is the code I'm currently using: $.ajax({ success: function(){ $('.post_container').append('test <br />'); }

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.